使用flutter中的firebase进行电话身份验证时出现内部服务器错误

50few1ms  于 2023-04-22  发布在  Flutter
关注(0)|答案(2)|浏览(126)

我是新来使用FirebaseFlutter .当做电话号码authentication在firebase我得到Internal server error消息.请帮助.
com.example.shubh_chintak是我的包名

I/zzh (18073): ForceRecaptchaFlow from phoneAuthOptions = false, ForceRecaptchaFlow from firebaseSettings = false
I/PlayCore(18073): UID: [10405]  PID: [18073] IntegrityService : requestIntegrityToken(IntegrityTokenRequest{nonce=1J4FG6Jr_wQLusX84KtIkX62iH537b731LPs_mt3i2g, cloudProjectNumber=551503664846})
I/PlayCore(18073): UID: [10405]  PID: [18073] IntegrityService : Initiate binding to the service.
I/PlayCore(18073): UID: [10405]  PID: [18073] IntegrityService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.integrityservice.IntegrityService})
I/PlayCore(18073): UID: [10405]  PID: [18073] IntegrityService : linkToDeath
I/PlayCore(18073): UID: [10405]  PID: [18073] OnRequestIntegrityTokenCallback : onRequestIntegrityToken
I/PlayCore(18073): UID: [10405]  PID: [18073] IntegrityService : Unbind from service.
W/System  (18073): Ignoring header X-Firebase-Locale because its value was null.
W/BpBinder(18073): Slow Binder: BpBinder transact took 290 ms, interface=com.google.android.gms.auth.api.phone.internal.ISmsRetrieverApiService, code=1 oneway=false
E/FirebaseAuth(18073): [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Internal error encountered.
D/FirebaseAuth(18073): Invoking original failure callbacks after phone verification failure for +916394994875, error - An internal error has occurred. [ Internal error encountered. ]

我正在使用以下方法对手机进行身份验证。

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:shubh_chintak/ShubhChintak/Buyer/BuyerCreateAccount.dart';
import 'package:shubh_chintak/ShubhChintak/Buyer/BuyerMainPage/BuyerMainPage.dart';
import 'package:shubh_chintak/ShubhChintak/constants.dart';
import 'package:shubh_chintak/ShubhChintak/reusableWidget.dart';
import 'package:shubh_chintak/ShubhChintakPostAPI/ShubhChintakHttp/ReturnBuyerIdHttp.dart';

class BuyerLoginPage extends StatefulWidget {
  static String? buyer_id1 = _BuyerLoginPageState.buyer_id;

  const BuyerLoginPage({Key? key}) : super(key: key);

  @override
  State<BuyerLoginPage> createState() => _BuyerLoginPageState();
}

class _BuyerLoginPageState extends State<BuyerLoginPage> {
  final FirebaseAuth auth = FirebaseAuth.instance;
  final _formKey = GlobalKey<FormState>();
  String? useBuyerId;
  static String? buyer_id;
  final TextEditingController _bPhoneController = TextEditingController();
  final TextEditingController _otpController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    var height = MediaQuery.of(context).size.height;
    var width = MediaQuery.of(context).size.width;
    var devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
    return Scaffold(
      body: Form(
        key: _formKey,
        child: SizedBox(
          height: double.infinity,
          width: double.infinity,
          child: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                SizedBox(
                  height: height * 0.25,
                ),
                reusableLocaleText(
                    "login", devicePixelRatio * 12, TextAlign.center),
                SizedBox(
                  height: height * 0.02,
                ),
                SizedBox(
                  height: height * 0.32,
                  width: width * 0.8,
                  child: Card(
                    shadowColor: kPrimaryColor,
                    shape: RoundedRectangleBorder(
                        borderRadius:
                            BorderRadius.circular(devicePixelRatio * 10),
                        side: const BorderSide(color: kPrimaryColor)),
                    child: Container(
                      padding: EdgeInsets.fromLTRB(
                        width * 0.08,
                        height * 0.03,
                        width * 0.08,
                        height * 0.02,
                      ),
                      child: Column(
                        children: <Widget>[
                          reusableTextFormField(
                            context,
                            "phone",
                            Icons.phone_android_sharp,
                            true,
                            true,
                            false,
                            false,
                            false,
                            false,
                            _bPhoneController,
                          ),
                          SizedBox(
                            height: height * 0.05,
                          ),
                          reusableElevatedButton(
                            context,
                            "sendotp",
                            25,
                            height * 0.055,
                            width * 0.8,
                            () async {
                              if (_bPhoneController.text.isEmpty) {
                                reusableSnackBar(
                                  context,
                                  RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(
                                        devicePixelRatio * 10),
                                  ),
                                  SnackBarBehavior.floating,
                                  reusableLocaleText("pleaseenterphonenumber",
                                      15, TextAlign.center),
                                );
                              } else if (_bPhoneController.text.length < 10 ||
                                  _bPhoneController.text
                                      .startsWith(0.toString())) {
                                reusableSnackBar(
                                  context,
                                  RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(
                                        devicePixelRatio * 10),
                                  ),
                                  SnackBarBehavior.floating,
                                  reusableLocaleText(
                                      "pleaseentervalidphonenumber",
                                      15,
                                      TextAlign.center),
                                );
                              } else {
                                FocusNode currentFocus = FocusScope.of(context);
                                if (currentFocus.hasPrimaryFocus) {
                                  currentFocus.unfocus();
                                }
                                if (_formKey.currentState!.validate()) {
                                  ReturnBuyerIdHttp returnBuyerLoginId =
                                      ReturnBuyerIdHttp();
                                  useBuyerId = await returnBuyerLoginId
                                      .returnBuyerID(_bPhoneController.text);
                                  buyer_id = returnBuyerLoginId.storeBuyerId;
                                  if (returnBuyerLoginId.storeBuyerIdStatus ==
                                      "Success") {
                                    await FirebaseAuth.instance
                                        .verifyPhoneNumber(
                                      phoneNumber:
                                          '+91${_bPhoneController.text}',
                                      verificationCompleted:
                                          (PhoneAuthCredential credential) {},
                                      verificationFailed:
                                          (FirebaseAuthException e) {},
                                      codeSent: (String verificationId,
                                          int? resendToken) {
                                        try {
                                          sendOTPAlertDialogBox(
                                            context,
                                            "enterotpsendonyourregisteredphone",
                                            _otpController,
                                            () async {
                                              try {

                                                // Create a PhoneAuthCredential with the code

                                                PhoneAuthCredential credential =
                                                    PhoneAuthProvider.credential(
                                                        verificationId:
                                                            verificationId,
                                                        smsCode:
                                                            _otpController.text);

                                                // Sign the user in (or link) with the credential

                                                await auth.signInWithCredential(
                                                    credential);                                               
                                                Navigator.push(
                                                  context,
                                                  MaterialPageRoute(
                                                    builder: (context) =>
                                                        const BuyerMainPage(),
                                                  ),
                                                );
                                              } catch (exception) {
                                                reusableSnackBar(
                                                  context,
                                                  RoundedRectangleBorder(
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            devicePixelRatio *
                                                                10),
                                                  ),
                                                  SnackBarBehavior.floating,
                                                  reusableLocaleText(
                                                      "pleaseentervalidotp",
                                                      15,
                                                      TextAlign.center),
                                                );
                                              }                                              
                                            },
                                            "ok",
                                            () {},
                                            "resendotp",
                                          );
                                        }
                                        on Exception catch (exception) {
                                          reusableSnackBar(
                                            context,
                                            RoundedRectangleBorder(
                                              borderRadius:
                                              BorderRadius.circular(
                                                  devicePixelRatio *
                                                      10),
                                            ),
                                            SnackBarBehavior.floating,
                                            reusableLocaleText(
                                                exception.toString(),
                                                15,
                                                TextAlign.center),
                                          );
                                        }
                                      },
                                      codeAutoRetrievalTimeout:
                                          (String verificationId) {},
                                    );                                    
                                  } else {
                                    reusableSnackBar(
                                      context,
                                      RoundedRectangleBorder(
                                        borderRadius: BorderRadius.circular(
                                            devicePixelRatio * 10),
                                      ),
                                      SnackBarBehavior.floating,
                                      reusableLocaleText(
                                          "Invalidlogincredntials",
                                          15,
                                          TextAlign.center),
                                    );
                                  }
                                }
                              }
                            },
                          ),
                          const Spacer(),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              reusableLocaleText(
                                "don'thaveaccount?",
                                devicePixelRatio * 5,
                                TextAlign.center,
                              ),
                              reusableTextButton(
                                context,
                                "create",
                                () {
                                  Navigator.pushReplacement(
                                    context,
                                    MaterialPageRoute(
                                      builder: (context) =>
                                          const BuyerCreateAccount(),
                                    ),
                                  );
                                },
                              )
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
trnvg8h3

trnvg8h31#

一路下调;

firebase_core: ^1.22.0
  firebase_auth: ^3.4.2.

1.然后删除pubspec.lock;

  1. Flutter 干净。
  2. Flutter PUB GET
    还有一些奇怪的错误不得不在dev_dependencies下添加firebase_core_platform_interface: 4.5.1
7cjasjjr

7cjasjjr2#

firebase_core软件包版本2.9.0有问题。请将其降级到2.8.0。这将解决此问题

相关问题