每个孩子必须布置一次。相关的引起错误的小部件为:脚手架

时间:2020-11-04 04:39:33

标签: android flutter dart country-codes

我开始使用flutter进行工作,之前没有任何错误..但是当我单击热重启时,出现了错误,并且出现了两个错误:

  1. 状态不佳:没有元素
  2. 每个孩子必须布置一次。

所以我想问大家,也许有人可以向我解释为什么我会得到这个错误,这是什么意思,以及如何消除它。

当我开始运行我的应用程序时,只显示了“全名”字段,“电话号码”字段就消失了。

好,所以我有这样的代码:

  String phoneNo, phoneName, smssent, verificationId;

  get verifiedSuccess => null;

  Future<void> verfiyPhone() async {
    final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verId) {
      this.verificationId = verId;
    };
    final PhoneCodeSent smsCodeSent = (String verId, [int forceCodeResent]) {
      this.verificationId = verId;
      smsCodeDialoge(context).then((value) {
        print("Code Sent");
      });
    };
    final PhoneVerificationCompleted verifiedSuccess = (AuthCredential auth) {};
    final PhoneVerificationFailed verifyFailed = (FirebaseAuthException e) {
      //(AuthException e)
      print('${e.message}');
    };
    await FirebaseAuth.instance.verifyPhoneNumber(
      phoneNumber: phoneNo,
      timeout: const Duration(seconds: 5),
      verificationCompleted: verifiedSuccess,
      verificationFailed: verifyFailed,
      codeSent: smsCodeSent,
      codeAutoRetrievalTimeout: autoRetrieve,
    );
  }

  Future<bool> smsCodeDialoge(BuildContext context) {
    return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return new AlertDialog(
            title: Text('Enter OTP'),
            content: TextField(
              onChanged: (value) {
                this.smssent = value;
              },
            ),
            contentPadding: EdgeInsets.all(10.0),
            actions: <Widget>[
              FlatButton(
                onPressed: () {
                  User currentUser = FirebaseAuth.instance.currentUser;
                  //FirebaseAuth.instance.currentUser.then(){
                  if (currentUser != null) {
                    //user!=null
                    Navigator.of(context).pop();
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => ManagementScreen()),
                    );
                  } else {
                    Navigator.of(context).pop();
                    signIn(smssent);
                  }
                },
                child: Text(
                  'Done',
                  style: TextStyle(color: Colors.black),
                ),
              ),
            ],
          );
        });
  }

  Future<void> signIn(String smsCode) async {
    final AuthCredential credential = PhoneAuthProvider.getCredential(
      verificationId: verificationId,
      smsCode: smsCode,
    );

    await FirebaseAuth.instance.signInWithCredential(credential).then((user) {
      Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => ManagementScreen(),
        ),
      );
    }).catchError((e) {
      print(e);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        title: Text('Phone Setup',
            style: TextStyle(color: Colors.grey, fontStyle: FontStyle.italic)),
        backgroundColor: Colors.transparent,
      ),
      body: Column(
        // mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(top: 30, left: 14),
            child: Container(
              child: Text('Make it easy for friends to join you on Clipstream.',
                  style: TextStyle(fontSize: 16)),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(16.0),
            child: TextFormField(
              keyboardType: TextInputType.name,
              onChanged: (value) {
                setState(() {
                  this.phoneName = value;
                });
              },
              decoration: InputDecoration(
                labelText: "Full name",
                border: new OutlineInputBorder(
                  borderRadius: new BorderRadius.circular(0.0),
                  borderSide: new BorderSide(),
                ),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(16.0),
               IntlPhoneField(
               decoration: InputDecoration(
                 labelText: 'Phone Number',
                 border: OutlineInputBorder(
                   borderSide: BorderSide(),
                 ),
               ),
               keyboardType: TextInputType.number,
               initialCountryCode: 'IN',
               onChanged: (value) {
                 setState(() {
                   this.phoneNo = value as String;
                 });
               },
             ),
          ),

0 个答案:

没有答案