

### 前提・実現したいこと

Flutter のアプリでFirebaseのAuthenticationを利用した電話番号認証をしたい。

### 発生している問題・エラーメッセージ

android studio を使っています。  
認証ボタンを押した瞬間に

[code]

    Xcode build done.                                           21.5s
        path: satisfied (Path is satisfied), interface: en0
    Configuring the default Firebase app...
    Configured the default Firebase app __FIRAPP_DEFAULT.
        path: satisfied (Path is satisfied), interface: en0
    Syncing files to device iPhone 11 Pro Max...
    *** First throw call stack:
    (
        0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
        1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
        2   CoreFoundation                      0x00007fff23c710bc +[NSException raise:format:] + 188
        3   Runner                              0x0000000103e97d81 -[FIRPhoneAuthProvider verifyPhoneNumber:UIDelegate:completion:] + 193
        4   Runner                              0x000000010440dc3d -[FLTFirebaseAuthPlugin handleMethodCall:result:] + 18109
        5   Flutter                             0x000000010600ddb5 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104
        6   Flutter                             0x0000000105fa1ba0 _ZNK7flutter21PlatformMessageRouter21HandlePlatf<…>
    Lost connection to device.
    
    
[/code]

のようなエラーが発生します。

### 自分のコード

[code]

    import 'package:flutter/material.dart';
    
    import 'package:firebase_auth/firebase_auth.dart';
    
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: MyHomePage(),
    
    //      initialRoute: '/',
    //      routes: {
    //        '/' : (context) => WelcomeClass(),
    //        '/LoginClass' : (context) => LoginClass(),
    //        '/SignUpClass' : (context) => SignUpClass(),
    //      },
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      String phoneNo;
      String smsCode;
      String verificationId;
    
      Future<void> verifyPhone() async {
        final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verId) {
          this.verificationId = verId;
        };
    
        final PhoneCodeSent smsCodeSent = (String verId, [int forceCodeResend]) {
          this.verificationId = verId;
          smsCodeDialog(context).then((value){
            print('signed in');
          });
        };
    
        final PhoneVerificationCompleted verificationSuccess = (AuthCredential user){
          print('Phone Verification Completed');
        };
    
        final PhoneVerificationFailed verificationFailed =
            (AuthException exception) {
          print('${exception.message}');
        };
    
        await FirebaseAuth.instance.verifyPhoneNumber(
          phoneNumber: this.phoneNo,
          codeAutoRetrievalTimeout: autoRetrieve,
          codeSent: smsCodeSent,
          timeout: const Duration(seconds: 60),
          verificationCompleted: verificationSuccess,
          verificationFailed: verificationFailed,
        );
      }
    
      Future<bool> smsCodeDialog(BuildContext context) {
        return showDialog(
            context: context,
            barrierDismissible: false,
            builder: (BuildContext context) {
              return new AlertDialog(
                title: Text('Enter sms code'),
                content: TextField(
                  onChanged: (value) {
                    this.smsCode = value;
                  },
                ),
                contentPadding: EdgeInsets.all(10),
                actions: <Widget>[
                  FlatButton(
                    child: Text('Done'),
                    onPressed: () {
                      FirebaseAuth.instance.currentUser().then((user) {
                        if (user != null) {
                          Navigator.of(context).pop();
                          Navigator.of(context)
                              .pushReplacementNamed('/SignUpClass');
                        } else {
                          Navigator.of(context).pop();
                          signIn();
                        }
                      });
                    },
                  )
                ],
              );
            });
      }
    
      signIn() {
        final AuthCredential credential = PhoneAuthProvider.getCredential(
            verificationId: verificationId, smsCode: smsCode);
    
        FirebaseAuth.instance.signInWithCredential(credential).then((user) {
          Navigator.of(context).pushReplacementNamed('/homepage');
        }).catchError((e) {
          print('Auth Credential Error : $e');
        });
      }
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Padding(
            padding: const EdgeInsets.all(38.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                TextField(
                  onChanged: (value) {
                    this.phoneNo = value;
                  },
                ),
                SizedBox(
                  height: 40,
                ),
                FlatButton(
                  child: Text("Send code"),
                  onPressed: verifyPhone,
                ), //FlatButton
              ], // Widget
            ),
          ), // Column
        );
      }
    }
    
    
    
    
[/code]

本当に困っています。よろしくお願いします。

### 補足情報（FW/ツールのバージョンなど）

  * Android Studio
  * Dart
  * Firebase Authentication

**マルチポスト先** :

  * <https://teratail.com/questions/243907>


CC BY-SA 4.0
2020-02-27T13:19:40.050
63412
2020-08-04T16:30:20.100
2020-02-27T14:24:20.847
32986
37991
question
android android-studio firebase flutter
Flutterの Firebaseの認証でトラブル


GoogleService-Info.plist は忘れているとか、間違っている思いますが。  
これは電話番号認証かどうか関係ないです、まずはアプリケーションのキーナンバーを入れてからGoogleService-
Info.plistをダウンロードするのが大切です、場合によって  
firebaseに接続できなかったのようです  
もう一度ちゃんとグーグルの説明を見て設定してください


CC BY-SA 4.0
2020-07-30T08:07:16.233
69114
2020-08-04T16:30:20.100
2020-08-04T16:30:20.100
41314
41314
63412
answer