Reputation: 19504
Is it possible to push all content up when open keyboard? (not only textField area, whole page push up)
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return BottomSheet();
},
isScrollControlled: true);
BottomSheet 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,
Upvotes: 4
Views: 3743
Reputation: 1150
In my case I am using the package flutter_screenutil, that now have a useInheritedMediaQuery field. I set it to true, and it is now working.
ScreenUtilInit(
useInheritedMediaQuery: true,
designSize: const Size(376, 812),
builder: (context, child) {
return const Scaffold(
resizeToAvoidBottomInset: true,
body: Column(
children: [
Spacer(),
TextField(),
],
),
);
},
);
Upvotes: 1
Reputation: 1
you can use this it will scroll
content up when you type :
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
****resizeToAvoidBottomInset: true, // set this to true****
appBar: AppBar(
title: Text('Flutter Keyboard Example'),
),
body: SingleChildScrollView( // wrap your content in a SingleChildScrollView widget
child: Center(
content )))
Upvotes: 0
Reputation: 13
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'),
),
],
),
),
),
Upvotes: 0
Reputation: 13057
Simply putting reverse=true
inside the SingleChildScrollView
will suffice.
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
reverse: true,
child: Container(
........
........
Upvotes: 4
Reputation: 370
You can simply give the widget a bottom
position of MediaQuery.of(context).viewInsets.bottom
if you are using a stack.
In your case, set margin :
to MediaQuery.of(context).viewInsets.bottom
instead of padding.
Upvotes: 1
Reputation: 25
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.
Upvotes: -1
Reputation: 104
Set resizeToAvoidBottomInset
property of the Scaffold as true.
Upvotes: -1