是否可以在打开键盘时将所有内容上推? (不只是textField区域,整个页面pushup)
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return BottomSheet();
},
isScrollControlled: true);
BottomSheet 类
class BottomSheet extends StatefulWidget {
@override
_BottomSheetState createState() => _BottomSheetState();
}
class _BottomSheetState extends State<BottomSheet> {
@override
Widget build(BuildContext context) {
return
SingleChildScrollView(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
child: Column(
children: <Widget>[...
这个俯卧撑我要点赞
但是电流输出是,
如果您使用堆栈,您可以简单地给小部件一个
bottom
位置MediaQuery.of(context).viewInsets.bottom
。
在您的情况下,将
margin :
设置为MediaQuery.of(context).viewInsets.bottom
而不是填充。
将您的整个小部件包裹在一个容器中,并像这样提供容器填充,它会起作用。
child: Container(
padding: EdgeInsets.only(
top: 25.0,
bottom: MediaQuery.of(context).viewInsets.bottom,
left: 25.0,
right: 25.0,
),
child: Form(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextFormField(
decoration: InputDecoration(
hintText: 'Email',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
keyboardType: TextInputType.emailAddress,
validator: (value) {
return _isEmailValid(value);
},
textInputAction: TextInputAction.next,
onSaved: (value) {},
controller: _emailController,
),
SizedBox(height: 10),
TextFormField(
obscureText: true,
decoration: InputDecoration(
hintText: 'Password',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
keyboardType: TextInputType.emailAddress,
validator: (value) {
return _isEmailValid(value);
},
textInputAction: TextInputAction.done,
onSaved: (value) {},
controller: _passwordController,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {},
child: const Text('Forgot Password'),
),
],
),
ElevatedButton(
style: ElevatedButton.styleFrom(
side: const BorderSide(width: 1.3, color: Colors.white),
shadowColor: Colors.white,
),
onPressed: () {},
child: const Text('Login'),
),
TextButton(
onPressed: () {},
child: Text('Not have any Accoung? Sign Up'),
),
],
),
),
),
您可以使用它,它会在您键入时向上滚动内容 '@override 小部件构建(BuildContext 上下文){ 返回 MaterialApp( 家:脚手架( resizeToAvoidBottomInset: true, // 将其设置为 true 应用栏:应用栏( title: Text('Flutter 键盘示例'), ), body: SingleChildScrollView( // 将您的内容包装在 SingleChildScrollView 小部件中 孩子:中心( 内容)))'
将脚手架的
resizeToAvoidBottomInset
属性设置为true。
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: //your code
);
}
)
这对我有用。也许尝试将填充物移动到容器内。