我正在尝试为我的应用程序添加电话身份验证,我在 Firebase 项目设置中添加了 SHA-1 指纹和 SHA-256 指纹。用两个测试号检查了它,完全没有问题。但是,当我尝试使用我尝试登录的设备中存在的真实电话号码登录时,我收到了 OTP,但是,当我进入 OTP 时,没有任何反应,它不会转到下一个屏幕, 它给了我一个 SMS 超时问题。 并且它说用户在输入 OTP 之前已经登录,但没有进入下一个屏幕。但是,再次输入另一个不在此设备中的电话号码时,它成功登录。请帮我解决这个问题。
Debug Log:Built build\app\outputs\flutter-apk\app-debug.apk.
D/ColorExSystemServiceHelper(23197): checkColorExSystemService className = com.google.android.gms.ads.identifier.service.AdvertisingIdService
Connecting to VM Service at ws://127.0.0.1:8522/3r-9AlZd-So=/ws
D/ColorExSystemServiceHelper(23197): checkColorExSystemService className = com.google.android.gms.ads.identifier.service.AdvertisingIdService
2
I/flutter (23197): [FB] SDK version: 9.0.0
D/ColorViewRootUtil(23197): nav gesture mode swipeFromBottom ignore false downY 1655 mScreenHeight 2340 mScreenWidth 1080 mStatusBarHeight 54 globalScale 1.125 nav mode 3 event MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=542.0, y[0]=1655.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=47040434, downTime=47040434, deviceId=5, source=0x1002, displayId=0 } rotation 0
D/ColorViewRootUtil(23197): nav gesture mode swipeFromBottom ignore false downY 1170 mScreenHeight 2340 mScreenWidth 1080 mStatusBarHeight 54 globalScale 1.125 nav mode 3 event MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=748.0, y[0]=1170.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=47042433, downTime=47042433, deviceId=5, source=0x1002, displayId=0 } rotation 0
W/IInputConnectionWrapper(23197): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(23197): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(23197): getSelectedText on inactive InputConnection
D/ColorViewRootUtil(23197): nav gesture mode swipeFromBottom ignore false downY 1125 mScreenHeight 2340 mScreenWidth 1080 mStatusBarHeight 54 globalScale 1.125 nav mode 3 event MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=625.0, y[0]=1125.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=47047954, downTime=47047954, deviceId=5, source=0x1002, displayId=0 } rotation 0
D/ColorExSystemServiceHelper(23197): checkColorExSystemService className = com.google.android.gms.chimera.GmsBoundBrokerService
W/System (23197): Ignoring header X-Firebase-Locale because its value was null.
D/ColorExSystemServiceHelper(23197): checkColorExSystemService className = com.google.android.gms.chimera.GmsApiService
2
W/System (23197): Ignoring header X-Firebase-Locale because its value was null.
D/FirebaseAuth(23197): Notifying id token listeners about user ( baDhBhRfpjcrdugxggA11812djf1 ).
D/FirebaseAuth(23197): Notifying auth state listeners about user ( baDhBhRfpjcrdugxggA11812djf1 ).
I/flutter (23197): user logged in
D/ColorViewRootUtil(23197): nav gesture mode swipeFromBottom ignore false downY 1231 mScreenHeight 2340 mScreenWidth 1080 mStatusBarHeight 54 globalScale 1.125 nav mode 3 event MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=158.0, y[0]=1231.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=47063652, downTime=47063652, deviceId=5, source=0x1002, displayId=0 } rotation 0
W/IInputConnectionWrapper(23197): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(23197): getSelectedText on inactive InputConnection
W/System (23197): Ignoring header X-Firebase-Locale because its value was null.
I/flutter (23197): [firebase_auth/session-expired] The sms code has expired. Please re-send the verification code to try again.
pubspec.yaml
cupertino_icons: ^1.0.0
firebase_core: ^0.5.2
firebase_auth: ^0.18.3
shared_preferences: ^0.5.12+4
cloud_firestore: ^0.14.3
modal_progress_hud: ^0.1.3
rflutter_alert: ^1.0.2
geolocator: ^6.1.6
google_sign_in: ^4.5.9
flutter_login_facebook: ^0.5.0
pinput: ^1.0.0
flutter_launcher_icons: ^0.8.
OTP 屏幕代码:
import 'package:pinput/pin_put/pin_put.dart';
import 'package:purohith_service/screens/home.dart';
class OTPScreen extends StatefulWidget {
final String phone;
OTPScreen({this.phone});
@override
_OTPScreenState createState() => _OTPScreenState();
}
class _OTPScreenState extends State<OTPScreen> {
// ignore: unused_field
String _verificatioCode;
final GlobalKey<ScaffoldState> _scaffoldkey = GlobalKey<ScaffoldState>();
final TextEditingController _pinPutController = TextEditingController();
final FocusNode _pinPutFocusNode = FocusNode();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orangeAccent.shade100,
body: Builder(
builder: (context) => Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Verify +91-${widget.phone}",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 26,
),
),
Container(
color: Colors.orangeAccent.shade50,
padding: EdgeInsets.only(
top: 20,
bottom: 20,
),
child: PinPut(
fieldsCount: 6,
focusNode: _pinPutFocusNode,
controller: _pinPutController,
submittedFieldDecoration: _pinPutDecoration.copyWith(
borderRadius: BorderRadius.circular(20.0),
),
selectedFieldDecoration: _pinPutDecoration,
followingFieldDecoration: _pinPutDecoration.copyWith(
borderRadius: BorderRadius.circular(5.0),
border: Border.all(
color: Colors.deepOrange,
),
),
onSubmit: (pin) async {
try {
await FirebaseAuth.instance
.signInWithCredential(PhoneAuthProvider.credential(
verificationId: _verificatioCode, smsCode: pin))
.then((value) async {
if (value.user != null) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
}
});
} catch (e) {
print(e);
}
},
),
),
],
),
),
),
);
}
_verifyPhone() async {
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: "+91${widget.phone}",
verificationCompleted: (PhoneAuthCredential credential) async {
await FirebaseAuth.instance
.signInWithCredential(credential)
.then((value) async {
if (value.user != null) {
print('user logged in');
}
});
},
verificationFailed: (FirebaseAuthException e) {
print(e.message);
},
codeSent: (String verId, int resendToken) {
setState(() {
_verificatioCode = verId;
});
},
codeAutoRetrievalTimeout: (String verId) {
setState(() {
_verificatioCode = verId;
});
},
timeout: Duration(seconds: 60));
}
BoxDecoration get _pinPutDecoration {
return BoxDecoration(
border: Border.all(color: Colors.deepOrange),
borderRadius: BorderRadius.circular(15.0),
);
}
@override
void initState() {
super.initState();
_verifyPhone();
}
}```