[英]how to push all content up when open keyboard
Is it possible to push all content up when open keyboard?是否可以在打开键盘时将所有内容上推? (not only textField area, whole page push up)
(不只是textField区域,整个页面push up)
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return BottomSheet();
},
isScrollControlled: true);
BottomSheet class底片 class
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>[...
I want to like this push-up,我想喜欢这个俯卧撑,
But Current output is,但当前 output 是,
You can simply give the widget a bottom
position of MediaQuery.of(context).viewInsets.bottom
if you are using a stack.如果您使用堆栈,您可以简单地为小部件提供
MediaQuery.of(context).viewInsets.bottom
的bottom
position。
In your case, set margin:
to MediaQuery.of(context).viewInsets.bottom
instead of padding.在您的情况下,将
margin:
设置为MediaQuery.of(context).viewInsets.bottom
而不是填充。
Wrap your whole widget inside a container and provide that container padding like this, it will work.将整个小部件包装在一个容器中,并像这样提供容器填充,它会起作用。
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'),
),
],
),
),
),
Set resizeToAvoidBottomInset
property of the Scaffold as true.将 Scaffold 的
resizeToAvoidBottomInset
属性设置为 true。
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: //your code
);
}
)
This works for me.这对我有用。 Maybe try moving your padding inside the container.
也许尝试将您的填充物移到容器内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.