Flutter - 在TextFormField上方显示键盘

11

我在一个应用中有某种登录页面。然而,当我聚焦于TextFormField时,键盘会覆盖字段,导致看不到任何内容。作为Android开发者,

我通常通过在清单中添加 android:windowSoftInputMode="adjustResize|stateHidden" 来解决这个问题。

在Flutter中如何解决呢?

代码:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: ListView(
        children: <Widget>[
          Center(child: Image(image: AssetImage("images/uhk.jpg"))),
          Form(
            key: formKey,
            child: Padding(
              padding: EdgeInsets.only(top: 20.0, left: 30.0, right: 30.0),
              child: Column(
                children: <Widget>[
                  TextFormField(
                      decoration:
                          new InputDecoration(labelText: "Přihlašovací jméno"),
                      maxLines: 1,
                      keyboardType: TextInputType.emailAddress,
                      onSaved: (String value) => ""),
                  TextFormField(
                      decoration: new InputDecoration(labelText: "Heslo"),
                      maxLines: 1,
                      obscureText: true,
                      onSaved: (String value) => ""),
                ],
              ),
            ),
          ),
          Padding(
              padding: EdgeInsets.only(top: 50.0, left: 30.0, right: 30.0),
              child: RaisedButton(
                  child: Text("Přihlásit se",
                      style: TextStyle(
                          fontSize: 16.0, color: Colors.white, height: 3.0)),
                  color: Colors.lightBlue,
                  onPressed: () => "")),
          Padding(
              padding: EdgeInsets.only(
                top: 20.0,
              ),
              child: Center(
                  child: FlatButton(
                  onPressed: () => "",
                  child: Text("Vytvořit účet",
                    style: TextStyle(fontSize: 14.0, color: Colors.grey)),
              ))),
        ],
      ),
}

Flutter使用硬件键盘,因此您的常规修复应该有效。 - Jonah Williams
在清单中,有那一行代码。可能我的UI代码中有一个错误(也许我只是使用了糟糕的包装器或其他东西)。 - Stepan
1个回答

4
 //Add this line "resizeToAvoidBottomInset: true," to your Scaffold and put your main container in ScrollView.

  @override
  Widget build(BuildContext context) {
     return Scaffold(
       resizeToAvoidBottomInset: true,
       key: _scaffoldKey,
       backgroundColor: Colors.white,
       body: SingleChildScrollView(    
          child: Container()
   ),
 );
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接