0

我有这个简单的登录屏幕,其中有两个TextFormField用于电子邮件和密码。当我尝试在这些文本框中输入文本时,每次我专注于文本字段输入数据时,键盘都会暂时出现并消失。

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

  @override
  _LogInPageState createState() => new _LogInPageState();
}

class _LogInPageState extends State<LogInPage> {
  static final formKey = new GlobalKey<FormState>();

  String _email;
  String _password;

  Widget padded({Widget child}) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 8.0),
      child: child,
    );
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
        child: Container(
            padding: const EdgeInsets.all(16.0),
            child: Column(children: [
              Card(
                  child:
                      Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
                Container(
                    padding: const EdgeInsets.all(16.0),
                    child: Form(
                        key: formKey,
                        child: Column(
                            crossAxisAlignment: CrossAxisAlignment.stretch,
                            children: [
                              padded(
                                  child: TextFormField(
                                key: Key('email'),
                                decoration: InputDecoration(labelText: 'Email'),
                                autocorrect: false,
                                validator: (val) => val.isEmpty
                                    ? 'Email can\'t be empty.'
                                    : null,
                                onSaved: (val) => _email = val,
                              )),
                              padded(
                                  child: TextFormField(
                                key: Key('password'),
                                decoration:
                                    InputDecoration(labelText: 'Password'),
                                obscureText: true,
                                autocorrect: false,
                                validator: (val) => val.isEmpty
                                    ? 'Password can\'t be empty.'
                                    : null,
                                onSaved: (val) => _password = val,
                              )),
                            ]))),
              ])),
            ])));
  }
}

这是表格: 在此处输入图像描述

编辑 我认为问题出在我调用此页面的方式上,如下所示。可以从 调用另一个页面FutureBuilder吗?

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("LogIn Demo"),
      ),
      body: FutureBuilder<FirebaseUser>(
        future: Provider.of<FireAuthService>(context).currentUser(),
        builder: (context, AsyncSnapshot<FirebaseUser> snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            if (snapshot.error != null) {
              return Text(snapshot.error.toString());
            }

            return snapshot.hasData
                ? UserProfilePage(snapshot.data)
                : LogInPage(title: 'Login');
          } else {
            return Container(
              child: CircularProgressIndicator(),
            );
          }
        },
      ),
    );
  }
4

1 回答 1

2

首先清理您的代码并重建,同时使用真实设备执行测试。

        static GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
于 2019-08-30T05:27:57.050 回答