Flutter - How to make a column screen scrollable

后端 未结 5 1116
广开言路
广开言路 2020-12-29 01:18

I\'m building a flutter app with a Login Screen. On focus on the text field(s), the screen is overflowed and i cannot scroll. I\'ve tried using a ListView.builder

5条回答
  •  抹茶落季
    2020-12-29 01:54

    Using SingleChildScrollView with Columns make your screen scrollable, and you can make your layout as above

    Here is how can you do it

    class MyHome extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return Scaffold(
            backgroundColor: Colors.white,
            body: SafeArea(
              bottom: false,
              child: Container(
                padding: EdgeInsets.only(left: 15, right: 15),
                height: double.infinity,
                width: double.infinity,
                child: SingleChildScrollView(
                    padding: EdgeInsets.only(bottom: 15),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.end,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        SizedBox(
                          height: 200.0,
                        ),
                        Card(
                          elevation: 8.0,
                          child: Container(
                            padding: EdgeInsets.all(10.0),
                            child: Column(
                              children: [
                                TextField(
                                  decoration: InputDecoration(
                                    prefixIcon: Icon(Icons.person),
                                    labelText: "Username or Email",
                                  ),
                                ),
                                SizedBox(
                                  height: 15.0,
                                ),
                                TextField(
                                  decoration: InputDecoration(
                                    prefixIcon: Icon(Icons.lock),
                                    labelText: "Password",
                                  ),
                                ),
                                SizedBox(
                                  height: 30.0,
                                ),
                                MaterialButton(
                                    height: 50.0,
                                    elevation: 5,
                                    minWidth: 300,
                                    onPressed: () {},
                                    shape: RoundedRectangleBorder(
                                      borderRadius: new BorderRadius.circular(30.0),
                                    ),
                                    color: Theme.of(context).primaryColor,
                                    disabledColor: Theme.of(context)
                                        .primaryColor
                                        .withOpacity(0.50),
                                    disabledElevation: 0,
                                    child: Text('SIGN IN',
                                        textAlign: TextAlign.center, style: TextStyle(color: Colors.white),))
                              ],
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 25.0,
                        ),
                        Row(
                          children: [
                            Expanded(child: Text("Don't Have a Account?")),
                            Text("Sign Up",
                                style: TextStyle(
                                  color: Colors.blue,
                                )),
                          ],
                        ),
                        SizedBox(
                          height: 50.0,
                        ),
                        Align(
                          alignment: Alignment.bottomCenter,
                          child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                            Text(
                              'New to App?',
                              style: TextStyle(color: Colors.black87),
                            ),
                            SizedBox(
                              width: 5,
                            ),
                            GestureDetector(
                              onTap: () {
                              },
                              child: Text(
                                "REGISTER", style: TextStyle(
                                color: Colors.blue,
                              )
                              ),
                            ),
                          ]),
                        )
                      ],
                    )),
              ),
            ));
      }
    }
    

提交回复
热议问题