0

I saw some solutions and implemented them. Look Ok on Emulator but doesn't work on Real Device (See screens). So when I click on a textField, the keyboard moves up as per in-focus Textfield and I am able to scroll, however does not happen in real device. Thanks in advance for your time.

BottomSheet launched at FloatinActionButton

showModalBottomSheet(
                isScrollControlled: true,
                backgroundColor: Colors.transparent,
                context: context,
                builder: (context) => SingleChildScrollView(
                  child: Container(
                      child: PostAd(),
                      padding: EdgeInsets.only(
                        bottom: MediaQuery.of(context).viewInsets.bottom,
                      )),
                ),
              );

The method PostAD shows several pages in Container (depending on Index chosen by user)

return Center(
      child: Container(
        height: MediaQuery.of(context).size.height / 1.5,
       
        child: Center(
          child: Container(
           child: Column(
              children: [
                Center(child: radioButtonCreate()), // Radio Buttons to select Page Index
                Expanded(child: kadFormList[formIndex]), //Pages i.e forms that has text field
              ],
            ),
          ),
        ),

enter image description here

Firaun
  • 369
  • 1
  • 5
  • 21

1 Answers1

0
import 'package:flutter/material.dart';
import 'package:keyboard_visibility/keyboard_visibility.dart';

main() => runApp(MaterialApp(
  home: Scaffold(
    body: MyForm(),
  ),
));

class MyForm extends StatefulWidget {
  MyForm() : super();

  @override
  State<StatefulWidget> createState() => MyFormState();
}

class MyFormState extends State<MyForm> {
  bool isKeyboardVisible = false;

  @override
  void initState() {
    super.initState();

    KeyboardVisibilityNotification().addNewListener(
      onChange: (bool visible) {
        if (!visible) {
          setState(() {
            FocusScope.of(context).unfocus();
          });
        }
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(20.0, 20, 20, 0),
      child: SingleChildScrollView(
        reverse: isKeyboardVisible ? true : false,
        child: Padding(
          padding: const EdgeInsets.fromLTRB(0, 0, 0, 100),
          child: Column(
            children: <Widget>[
              for (int i=0; i<100; i++) TextField()
            ],
          ),
        ),
      ),
    );
  }
}