実現したいこと
FlutterアプリでFirebaseの電話番号認証の実装したい。
前提
テスト用の電話番号を入力した後、以下のエラーメッセージが発生し、画面が進みません。
ログイン方法として電話番号を有効にしており、アプリの SHA-1 ハッシュを設定済みです。
発生している問題・エラーメッセージ
E/zzf ( 4951): Problem retrieving SafetyNet Token: 7: D/EGL_emulation( 4951): app_time_stats: avg=223.10ms min=5.63ms max=2347.46ms count=13 I/zzpz ( 4951): Provider GmsCore_OpenSSL not available W/System ( 4951): Ignoring header X-Firebase-Locale because its value was null. W/Parcel ( 4951): Expecting binder but got null! D/TrafficStats( 4951): tagSocket(164) with statsTag=0xffffffff, statsUid=-1 D/AutofillManager( 4951): Fill dialog is enabled:false, hints=[password, passwordAuto, creditCardNumber, creditCardSecurityCode, creditCardExpirationDate]
該当のソースコード
import 'package:flutter/material.dart'; import 'package:firebase_auth/firebase_auth.dart'; void main() async{ runApp(const TelIdentificationPage()); } class TelIdentificationPage extends StatefulWidget { const TelIdentificationPage({super.key}); @override State<TelIdentificationPage> createState() => _TelIdentificationPage(); } class _TelIdentificationPage extends State<TelIdentificationPage> { String iphone = ''; String verificationId = ''; String smsCode = ''; void _verifyPhoneNumber(BuildContext context) async { String phone = iphone; FirebaseAuth auth = FirebaseAuth.instance; await auth.verifyPhoneNumber( phoneNumber: phone, timeout: const Duration(seconds: 60), verificationCompleted: (PhoneAuthCredential credential) async { await auth.signInWithCredential(credential); }, verificationFailed: (FirebaseAuthException e) { if (e.code == 'invalid-phone-number') { debugPrint('電話番号が正しくありません。'); } }, codeSent: (String verificationId, int? resendToken) { this.verificationId = verificationId; smsCodeDialog(context).then((value) { print('sign in'); }); }, codeAutoRetrievalTimeout: (String verificationId) { this.verificationId = verificationId; }, ); } @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData(primarySwatch: Colors.blue), home: Scaffold( appBar: AppBar( title: const Text('xxxx'), ), body: Center( child: Column( children:[ SizedBox( width:150, height: 50, child: TextFormField( keyboardType: TextInputType.phone, onChanged: (value) { iphone= value; } ), ), ElevatedButton( style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.blue), ), onPressed: () { _verifyPhoneNumber(context); }, child: const Text('送信'), ), ] ), ), ), ); } Future smsCodeDialog(BuildContext context) { return showDialog( context: context, barrierDismissible: false, builder: (BuildContext content) { return AlertDialog( title: const Text('確認コードを入力してください'), content: TextField( keyboardType: TextInputType.number, onChanged: (String value){ smsCode = value; }, ), contentPadding: const EdgeInsets.all(10), actions: const <Widget>[ ElevatedButton( onPressed: null, child: Text( "完了", style: TextStyle(color: Colors.white), ) ), ], ); } ); } }
宜しくお願いします。
補足情報(FW/ツールのバージョンなど)
Android Studio
Dart
Firebase Authentication

0 コメント