List view is not Scroll able when I put this property resizeToAvoidBottomInset : false,

Issue

I am creating a page where I make some TextFormField and put them into a listview and that listview is inside a stack widget. when I click on TextFormField keyboard appears and background image (that I put into a center tag in a stack) adjust according to the remaining screen after. I use resizeToAvoidBottomInset : false, to avoid to screen resizing but by putting this I am unable to scroll my listview that was scrollable without this property resizeToAvoidBottomInset : false.

import 'package:flutter/material.dart';
import 'main.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
  runApp(MaterialApp(
    home: Contactus(),
  ));
}

class Contactus extends StatelessWidget {
  static final _formkey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
    return Scaffold(
        resizeToAvoidBottomInset: false,
        body: Stack(
          children: <Widget>[
            Center(
              child: Image.asset(
                'imges/bg.png',
                fit: BoxFit.fill,
              ),
            ),
            Center(
              child: ListView(
                children: <Widget>[
                  Container(
                      child: Stack(
                    children: <Widget>[
                      Form(
                        key: _formkey,
                        child: Padding(
                          padding: const EdgeInsets.only(
                              right: 80, top: 10, bottom: 10, left: 80),
                          child: Column(
                            children: <Widget>[
                              Stack(
                                children: <Widget>[
                                  Center(
                                    child: Container(
                                      margin: EdgeInsets.only(
                                          left: 20, right: 20, top: 0),
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.center,
                                        children: <Widget>[
                                          Expanded(
                                            child: Container(
                                              decoration: BoxDecoration(
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(12.0)),
                                                color: Colors.white,
                                              ),
                                              child: TextFormField(
                                                textAlign: TextAlign.center,
                                                style: TextStyle(
                                                    color: Colors.white,
                                                    fontWeight:
                                                        FontWeight.w300),
                                                decoration: InputDecoration(
                                                  hintText: "Your First Name",
                                                  hintStyle: TextStyle(
                                                      fontWeight:
                                                          FontWeight.w300,
                                                      color: Colors.black),
                                                  prefixIcon:
                                                      Icon(Icons.account_box),
                                                  errorStyle: TextStyle(
                                                    color: Colors.yellowAccent,
                                                    fontSize: 15,
                                                  ),
                                                  border: OutlineInputBorder(
//                      borderRadius: BorderRadius.circular(25.0),
                                                    borderSide: BorderSide(),
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                          SizedBox(
                                            width: 20.0,
                                          ),
                                          Expanded(
                                            child: Container(
                                              decoration: BoxDecoration(
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(12.0)),
                                                color: Colors.white,
                                              ),
                                              child: TextFormField(
                                                textAlign: TextAlign.center,
                                                style: TextStyle(
                                                    color: Colors.white,
                                                    fontWeight:
                                                        FontWeight.w300),
                                                decoration: InputDecoration(
                                                  hintText: "Your Last Name",
                                                  hintStyle: TextStyle(
                                                      fontWeight:
                                                          FontWeight.w300,
                                                      color: Colors.black),
                                                  prefixIcon:
                                                      Icon(Icons.account_box),
                                                  errorStyle: TextStyle(
                                                    color: Colors.yellowAccent,
                                                    fontSize: 15,
                                                  ),
                                                  border: OutlineInputBorder(
//                      borderRadius: BorderRadius.circular(25.0),
                                                    borderSide: BorderSide(),
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                  SizedBox(
                                    height: 10.0,
                                  ),
                                  Center(
                                    child: Container(
                                      margin: EdgeInsets.only(
                                          left: 20, right: 20, top: 60),
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.center,
                                        children: <Widget>[
                                          Expanded(
                                            child: Container(
                                              decoration: BoxDecoration(
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(12.0)),
                                                color: Colors.white,
                                              ),
                                              child: TextFormField(
                                                textAlign: TextAlign.center,
                                                style: TextStyle(
                                                    color: Colors.white,
                                                    fontWeight:
                                                        FontWeight.w300),
                                                decoration: InputDecoration(
                                                  hintText: "Email ADDRESS",
                                                  hintStyle: TextStyle(
                                                      fontWeight:
                                                          FontWeight.w300,
                                                      color: Colors.black),
                                                  prefixIcon: Icon(Icons.email),
                                                  errorStyle: TextStyle(
                                                    color: Colors.yellowAccent,
                                                    fontSize: 15,
                                                  ),
                                                  border: OutlineInputBorder(
//                      borderRadius: BorderRadius.circular(25.0),
                                                    borderSide: BorderSide(),
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                          SizedBox(
                                            width: 20.0,
                                          ),
                                          Expanded(
                                            child: Container(
                                              decoration: BoxDecoration(
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(12.0)),
                                                color: Colors.white,
                                              ),
                                              child: TextFormField(
                                                textAlign: TextAlign.center,
                                                style: TextStyle(
                                                    color: Colors.white,
                                                    fontWeight:
                                                        FontWeight.w300),
                                                decoration: InputDecoration(
                                                  hintText: "Phone Number",
                                                  hintStyle: TextStyle(
                                                      fontWeight:
                                                          FontWeight.w300,
                                                      color: Colors.black),
                                                  prefixIcon: Icon(Icons.phone),
                                                  errorStyle: TextStyle(
                                                    color: Colors.yellowAccent,
                                                    fontSize: 15,
                                                  ),
                                                  border: OutlineInputBorder(
//                      borderRadius: BorderRadius.circular(25.0),
                                                    borderSide: BorderSide(),
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                  SizedBox(
                                    height: 10.0,
                                  ),
                                  Center(
                                    child: Container(
                                      margin: EdgeInsets.only(
                                          left: 20, right: 20, top: 120),
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.center,
                                        children: <Widget>[
                                          Expanded(
                                            child: Container(
                                              decoration: BoxDecoration(
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(15.0)),
                                                color: Colors.white,
                                              ),
                                              child: TextFormField(
                                                style: TextStyle(
                                                  color: Colors.white,
                                                  fontWeight: FontWeight.w300,
                                                ),
                                                validator: (String value) {
                                                  if (value.isEmpty) {
                                                    return 'please add some value';
                                                  }
                                                },
                                                maxLines: 8,
                                                decoration: InputDecoration(
                                                  hintText:
                                                      "Your message starts here.....",
                                                  focusedBorder:
                                                      OutlineInputBorder(
                                                          borderSide: BorderSide(
                                                              color: Colors
                                                                  .transparent)),
                                                  hintStyle: TextStyle(
                                                      fontWeight:
                                                          FontWeight.w300,
                                                      color: Colors.black),
                                                  prefixIcon: Padding(
                                                    padding:
                                                        const EdgeInsetsDirectional
                                                            .only(top: 0),
                                                    child: Icon(Icons
                                                        .message), // myIcon is a 48px-wide widget.
                                                  ),
                                                  errorStyle: TextStyle(
                                                    color: Colors.yellowAccent,
                                                    fontSize: 15,
                                                  ),
                                                ),
                                              ),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                  SizedBox(
                                    height: 10.0,
                                  ),
                                  Center(
                                    child: Container(
                                      margin:
                                          EdgeInsets.only(right: 20, top: 290),
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.end,
                                        children: <Widget>[
                                          Container(
                                            width: 100,
                                            height: 56,
                                            decoration: BoxDecoration(
                                              borderRadius: BorderRadius.all(
                                                  Radius.circular(12.0)),
                                              color: Colors.white,
                                            ),
                                            child: FlatButton(
                                              color: Colors.white,
                                              onPressed: () {
                                                if (_formkey.currentState
                                                    .validate()) {
                                                  _launchURL(
                                                      'd.m.javid95@gmail.com',
                                                      'Flutter Email Test',
                                                      'Hello Flutter');
                                                }
                                              },
                                              child: Text('Send mail'),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                ],
                              )
                            ],
                          ),
                        ),
                      ),
                    ],
                  ))
                ],
              ),
            ),
            FlatButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Icon(
                Icons.arrow_back,
                color: Colors.white,
                size: 30,
              ),
//                color: Colors.transparent,
            ),
          ],
        ));
  }
}

_launchURL(String toMailId, String subject, String body) async {
  var url = 'mailto:$toMailId?subject=$subject&body=$body';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

I want list-view scroll able without resizing the screen on key opening.

Solution

The reason is that the screen height is enough to display your ListView items, setting resizeToAvoidBottomInset : false didn’t stop your list from functioning. You can confirm this by adding more items to your list (in my case I added a second copy of your Container) and the list worked fine.

Answered By – Mazin Ibrahim

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *