[英]Flutter: How to make a ListView's height match_parent in Flutter
ListView's height should be as windows's height. ListView 的高度应该与窗口的高度相同。 So when keyboard opens, user can scroll down to see the widgets which covered by keyboard.因此,当键盘打开时,用户可以向下滚动以查看键盘覆盖的小部件。 And Widgets shouldn't change their position.并且小部件不应更改其 position。 I've used Align widget to position them, and wrapped with a Stack widget.我使用 Align 小部件到 position 它们,并用 Stack 小部件包装。 In other words: it should be exactly as Instagram login page.换句话说:它应该与 Instagram 登录页面完全一样。
I hope this helps: demo: https://i.ibb.co/g7C3K7K/dmeo.gif我希望这会有所帮助:演示: https://i.ibb.co/g7C3K7K/dmeo.gif
import 'package:flutter/material.dart';
class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final key = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: key,
body: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"Welcome to the login page",
style: Theme.of(context).textTheme.display1,
),
TextField(
decoration: InputDecoration(hintText: "Name"),
),
FlatButton(
onPressed: () {
key.currentState.showSnackBar(SnackBar(
content:
Text("I won't say your name but stay home, stay safe!"),
));
},
child: Text("Say my name"))
],
),
),
),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.