4

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,

need to like this push-up, here

But Current output is,

current output here

BIS Tech
  • 17,000
  • 12
  • 99
  • 148

7 Answers7

2

Simply putting reverse=true inside the SingleChildScrollView will suffice.

Widget build(BuildContext context) {
  return Scaffold(
    body: SafeArea(
      child: SingleChildScrollView(
        reverse: true,
        child: Container(
          ........
          ........ 

enter image description here

Astik Anand
  • 12,757
  • 9
  • 41
  • 51
1

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.

Kelvin Mboto
  • 361
  • 6
  • 15
1

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(),
            ],
          ),
        );
      },
    );
khan
  • 1,099
  • 1
  • 11
  • 21
0

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'),
            ),
          ],
        ),
      ),
    ),
Syscall
  • 19,327
  • 10
  • 37
  • 52
Ali Wajdan
  • 13
  • 2
0

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 )))
Esmaeil Ahmadipour
  • 840
  • 1
  • 11
  • 32
-1

Set resizeToAvoidBottomInset property of the Scaffold as true.

Manas Gupta
  • 104
  • 3
-1
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.