4

I'm using flutter to make a page that someone can comment.And the page is shown by showModalBottomSheet. but the textfield is hidden by the keyboard when the keyboard showing in the front.

    flutter doctor output:
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14 18A391, locale zh-Hans-CN)
    [!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
     ✗ Android license status unknown.
    [✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    [✓] Android Studio (version 3.1)
    [!] VS Code (version 1.30.0)
    [✓] Connected device (1 available)

Code snippet:

showModalBottomSheet(
            context: context,
            builder: (BuildContext sheetContext) {
              return new Container(
                height: 230.0,
                padding: const EdgeInsets.all(20.0),
                child: ListView(
                  children: <Widget>[
                    new Column(
                      children: <Widget>[
                        new Row(
                          children: <Widget>[
                            new Text(isMainFloor ? "reply author" :"reply"),
                            new Expanded(
                                child: new Text(
                              title,
                              style: new TextStyle(color: const Color(0xFF63CA6C)),
                            )),
                            new InkWell(
                              child: new Container(
                                padding:
                                    const EdgeInsets.fromLTRB(10.0, 6.0, 10.0, 6.0),
                                decoration: new BoxDecoration(
                                    border: new Border.all(
                                      color: const Color(0xFF63CA6C),
                                      width: 1.0,
                                    ),
                                    borderRadius: new BorderRadius.all(
                                        new Radius.circular(6.0))),
                                child: new Text( "send",
                                  style:
                                      new TextStyle(color: const Color(0xFF63CA6C)),
                                ),
                              ),
                              onTap: () {

                                sendReply(authorId);
                              },
                            )
                          ],
                        ),
                        new Container(
                          height: 10.0,
                        ),
                        new TextFormField(
                          maxLines: 5,
                          controller: _inputController,
                          focusNode: _focusNode,
                          decoration: new InputDecoration(
                              hintText: "balabala……",
                              hintStyle:
                                  new TextStyle(color: const Color(0xFF808080)),
                              border: new OutlineInputBorder(
                                borderRadius: const BorderRadius.all(
                                    const Radius.circular(10.0)),
                              )),
                        ),
                        new Padding(
                            padding: EdgeInsets.only(
                                bottom: MediaQuery.of(context).viewInsets.bottom)),
                      ],
                    )
                  ],
                ),
              );
            });
      }
Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
Sheng Qiu
  • 41
  • 1
  • 4
  • 1
    Did you check https://stackoverflow.com/questions/54176233/textfield-gets-hidden-when-the-keyboard-pops-in – Günter Zöchbauer Jan 15 '19 at 09:42
  • 1
    WorkAround is - remove `height: 230.0,` from `Container` & Wrap Listview in Padding Widget - `Padding( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom), child: ListView(....` & remove last padding Widget. – anmol.majhail Jan 15 '19 at 09:59
  • Possible duplicate of [TextField gets hidden when the keyboard pops in](https://stackoverflow.com/questions/54176233/textfield-gets-hidden-when-the-keyboard-pops-in) – Jerome Escalante Jan 15 '19 at 10:08
  • @anmol.majhail i tried your method.But it is only a small bit use, it only moved small disances,the input can not show completely.i guess the BottomSheet maybe the special widget that can not show well. i tried these codes wrapped in a Scaffod,and it worked well. – Sheng Qiu Jan 15 '19 at 12:10
  • @ShengQiu `BottomSheet` has MaxHeight Constraint - so won't increase in height – anmol.majhail Jan 15 '19 at 12:33
  • @anmol.majhail all right.if i wanna to Implement requirements like i described before. any good ideas? – Sheng Qiu Jan 17 '19 at 01:48

1 Answers1

0

I had issues running the minimal repro provided. However, if you're using a constant height for the widget and the widget exceeds the SoftKeyboard displayed on the device, it's likely that the widget overflowed. I suggest using widgets that can adapt to the view size (i.e. Expanded) if you'd like to keep the constant height on the TextField.

Here's a sample code that you can try. I've used Expanded for displaying the details on screen while keeping the constant height on the TextField Container.

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var _inputController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Expanded(
              child: Container(
                color: Colors.lightBlueAccent,
                child: ListView.builder(
                  itemCount: 15,
                  itemBuilder: (context, index) {
                    return ListTile(title: Text("List Item $index"));
                  },
                ),
              ),
            ),
            Container(
              height: 120,
              color: Colors.tealAccent,
              child: TextFormField(
                maxLines: 5,
                controller: _inputController,
                decoration: new InputDecoration(
                  hintText: "Text input",
                  hintStyle: new TextStyle(color: Colors.black),
                  border: new OutlineInputBorder(
                    borderRadius:
                        const BorderRadius.all(const Radius.circular(10.0)),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Here's how it looks running

demo

Omatt
  • 8,564
  • 2
  • 42
  • 144