Flutter-键盘不出现,并且不停留在所选字段下

raf*_*b21 2 dart flutter

键盘不能与一起正常使用TextField

我在代码14下面放了代码TextField,但是例如在字段14中单击时,键盘没有出现,也不在TextField点击的下方。

您能帮我解决这个键盘问题吗?这个问题没有出现,也没有让我进入所选的领域吗?

在此处输入图片说明

import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(home: new HomePage()));
}

class HomePage extends StatefulWidget {
  @override
  HomePageState createState() => new HomePageState();
}

class HomePageState extends State<HomePage> {
  final TextEditingController _controller = new TextEditingController();

  @override
  Widget build(BuildContext context) {    
    return new Scaffold(
      body: new Stack(
        children: <Widget>[
          new ListView(
            shrinkWrap: true,
            children: <Widget>[
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 1',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 2',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 3',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 4',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 5',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 6',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 7',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 8',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 9',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 10',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 11',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 12',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 13',
                ),
              ),
              new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                  hintText: 'Type something 14',
                ),
              ),             
            ],
          )          
        ]
      )
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

And*_*sky 7

我有同样的问题,但就我而言,它在Key对象中

await showDialog(
    context: context,
    barrierDismissible: false,
    builder: (context) {
      final _textKey = GlobalKey<FormState>();
      TextEditingController controller = TextEditingController();

      return AlertDialog(
        title: Text('Load conference'),
        content: Form(
          key: _textKey,
          child: TextFormField(
            controller: controller,
            validator: (str) {
              if (str.isEmpty) {
                return 'Empty url';
              } else if (str.length >= 4 && str.substring(0, 4).toLowerCase() != 'http') {
                return 'Url has to start from \'http\'';
              }
            },
          ),
          onChanged: () {
            if (controller.text.isNotEmpty) {
              _textKey.currentState.validate();
            }
          },
        ),
Run Code Online (Sandbox Code Playgroud)

通过设置键静态类字段解决了问题

static final _textKey = GlobalKey<FormState>();
Run Code Online (Sandbox Code Playgroud)


Col*_*son 6

您不应该让所有文本字段共享相同的文本TextEditingController。每个控制器使用一个单独的控制器。

  • 听起来您好像遇到了https://github.com/flutter/flutter/issues/10826,该文件已针对此问题发布了解决方法,直到最终解决方案就绪为止。 (3认同)