Firebase 在flatter中发送电话身份验证

Firebase 在flatter中发送电话身份验证,firebase,flutter,Firebase,Flutter,我的颤振代码在使用firebase将otp发送到电话号码进行身份验证时非常有效。 但后来我重新启动电脑后,它就不再工作了。输入电话号码后,通常会向输入的电话号码发送otp,但不再发送。我不知道怎么了 login.dart--输入电话号码的位置 class LoginScreen extends StatefulWidget { @override _LoginScreenState createState() => _LoginScreenState(); } class _Lo

我的颤振代码在使用firebase将otp发送到电话号码进行身份验证时非常有效。 但后来我重新启动电脑后,它就不再工作了。输入电话号码后,通常会向输入的电话号码发送otp,但不再发送。我不知道怎么了

login.dart--输入电话号码的位置

class LoginScreen extends StatefulWidget {
  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
  TextEditingController _controller = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Phone Auth'),
      ),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(children: [
              Container(
                margin: EdgeInsets.only(top: 60),
                child: Center(
                  child: Text(
                    'Phone Authentication',
                    style: TextStyle(fontWeight: FontWeight.bold, fontSize: 28),
                  ),
                ),
              ),
              Container(
                margin: EdgeInsets.only(top: 40, right: 10, left: 10),
                child: TextField(
                  decoration: InputDecoration(
                    hintText: 'Phone Number',
                    prefix: Padding(
                      padding: EdgeInsets.all(4),
                      child: Text('+234'),
                    ),
                  ),
                  maxLength: 10,
                  keyboardType: TextInputType.number,
                  controller: _controller,
                ),
              )
            ]),
            Container(
              margin: EdgeInsets.all(10),
              width: double.infinity,
              child: FlatButton(
                color: Colors.blue,
                onPressed: () {
                  Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => OTPScreen(_controller.text)));
                },
                child: Text(
                  'Next',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

由于某些原因,API未连接。请尝试更改您的网络区域,然后再试一次,希望
vpn
能帮助您。

您能提供发送OTP所用的代码吗?仅从控制台输出很难知道出了什么问题。我已经更新了问题:您使用的是什么版本的
firebase\u auth
?firebase\u auth:^0.20.1今天早些时候它工作正常
class OTPScreen extends StatefulWidget {
  final String phone;
  OTPScreen(this.phone);
  @override
  _OTPScreenState createState() => _OTPScreenState();
}

class _OTPScreenState extends State<OTPScreen> {
  final GlobalKey<ScaffoldState> _scaffoldkey = GlobalKey<ScaffoldState>();
  String _verificationCode;
  final TextEditingController _pinPutController = TextEditingController();
  final FocusNode _pinPutFocusNode = FocusNode();
  final BoxDecoration pinPutDecoration = BoxDecoration(
    color: const Color.fromRGBO(43, 46, 66, 1),
    borderRadius: BorderRadius.circular(10.0),
    border: Border.all(
      color: const Color.fromRGBO(126, 203, 224, 1),
    ),
  );
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldkey,
      appBar: AppBar(
        title: Text('OTP Verification'),
      ),
      body: Column(
        children: [
          Container(
            margin: EdgeInsets.only(top: 40),
            child: Center(
              child: Text(
                'Verify +234-${widget.phone}',
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 26),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(30.0),
            child: PinPut(
              fieldsCount: 6,
              textStyle: const TextStyle(fontSize: 25.0, color: Colors.white),
              eachFieldWidth: 40.0,
              eachFieldHeight: 55.0,
              focusNode: _pinPutFocusNode,
              controller: _pinPutController,
              submittedFieldDecoration: pinPutDecoration,
              selectedFieldDecoration: pinPutDecoration,
              followingFieldDecoration: pinPutDecoration,
              pinAnimationType: PinAnimationType.fade,
              onSubmit: (pin) async {
                try {
                  await FirebaseAuth.instance
                      .signInWithCredential(PhoneAuthProvider.credential(
                          verificationId: _verificationCode, smsCode: pin))
                      .then((value) async {
                    if (value.user != null) {
                      Navigator.pushAndRemoveUntil(
                          context,
                          MaterialPageRoute(builder: (context) => Home()),
                          (route) => false);
                    }
                  });
                } catch (e) {
                  FocusScope.of(context).unfocus();
                  _scaffoldkey.currentState
                      .showSnackBar(SnackBar(content: Text('invalid OTP')));
                }
              },
            ),
          )
        ],
      ),
    );
  }

  _verifyPhone() async {
    await FirebaseAuth.instance.verifyPhoneNumber(
        phoneNumber: '+234${widget.phone}',
        verificationCompleted: (PhoneAuthCredential credential) async {
          await FirebaseAuth.instance
              .signInWithCredential(credential)
              .then((value) async {
            if (value.user != null) {
              Navigator.pushAndRemoveUntil(
                  context,
                  MaterialPageRoute(builder: (context) => Home()),
                  (route) => false);
            }
          });
        },
        verificationFailed: (FirebaseAuthException e) {
          print(e.message);
        },
        codeSent: (String verficationID, int resendToken) {
          setState(() {
            _verificationCode = verficationID;
          });
        },
        codeAutoRetrievalTimeout: (String verificationID) {
          setState(() {
            _verificationCode = verificationID;
          });
        },
        timeout: Duration(seconds: 120));
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _verifyPhone();
  }
}
E/zzf     ( 9889): Problem retrieving SafetyNet Token: 7: 
I/zzjy    ( 9889): Provider GmsCore_OpenSSL not available
W/System  ( 9889): Ignoring header X-Firebase-Locale because its value was null.
D/EGL_emulation( 9889): eglMakeCurrent: 0xaec552c0: ver 2 0 (tinfo 0xa25bbee0)
E/FirebaseAuth( 9889): [GetAuthDomainTask] IOException occurred: java.net.UnknownHostException: Unable to resolve host "www.googleapis.com": No address associated with hostname
E/zzf     ( 9889): Failed to get reCAPTCHA token - calling backend without app verification
I/FirebaseAuth( 9889): [FirebaseAuth:] Preparing to create service connection to fallback implementation
D/EGL_emulation( 9889): eglMakeCurrent: 0xaec552c0: ver 2 0 (tinfo 0xa25bbee0)
E/Surface ( 9889): getSlotFromBufferLocked: unknown buffer: 0x9a91d440
W/System  ( 9889): Ignoring header X-Firebase-Locale because its value was null.
E/FirebaseAuth( 9889): [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Unable to resolve host "www.googleapis.com":No address associated with hostname
IOException occurred: java.net.UnknownHostException: Unable to resolve host "www.googleapis.com": No address associated with hostname