Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter Web with Firebase Phone Auth- 'UnimplementedError' #2693

Closed
aislingorg opened this issue Jun 3, 2020 · 3 comments
Closed

Flutter Web with Firebase Phone Auth- 'UnimplementedError' #2693

aislingorg opened this issue Jun 3, 2020 · 3 comments
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested.

Comments

@aislingorg
Copy link

I'm getting

Expected a value of type 'PlatformException', but got one of type 'UnimplementedError' at Object.throw_ [as throw] (http://localhost:37847/dart_sdk.js:4773:11) at Object.castError (http://localhost:37847/dart_sdk.js:4746:15) at Object.cast [as as] (http://localhost:37847/dart_sdk.js:5055:17) at dart.LegacyType.new.as (http://localhost:37847/dart_sdk.js:6517:60) at mob_home._MobHomeState.new.verifyPhone (http://localhost:37847/packages/VirtualClassroom/screens/mobile/mob_home.dart.lib.js:729:49) at verifyPhone.throw (<anonymous>)

@TahaTesser
Copy link

TahaTesser commented Jun 3, 2020

Hi @aislingorg
Make sure you've phone authentication enabled in firebase console

Screenshot 2020-06-03 at 4 04 23 PM

If the problem persist, can you please provide your flutter doctor -v, your flutter run --verbose and a minimal complete reproducible code sample.
Thank you"

@TahaTesser TahaTesser added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jun 3, 2020
@aislingorg
Copy link
Author

aislingorg commented Jun 3, 2020

flutter doctor -v

[✓] Flutter (Channel beta, 1.18.0-11.1.pre, on Linux, locale en_US.UTF-8)
    • Flutter version 1.18.0-11.1.pre at /home/green_dome/flutter
    • Framework revision 2738a1148b (3 weeks ago), 2020-05-13 15:24:36 -0700
    • Engine revision ef9215ceb2
    • Dart version 2.9.0 (build 2.9.0-8.2.beta)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /home/green_dome/Android/Sdk
    • Platform android-29, build-tools 29.0.2
    • Java binary at: /media/green_dome/_dde_data2/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Android Studio (version 3.6)
    • Android Studio at /media/green_dome/_dde_data2/android-studio
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] IntelliJ IDEA Community Edition (version 2019.1)
    • IntelliJ at /usr/share/intellij-idea-community
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8593

[✓] VS Code (version 1.45.1)
    • VS Code at /usr/share/code
    • Flutter extension version 3.11.0

[✓] Connected device (2 available)
    • Web Server • web-server • web-javascript • Flutter Tools
    • Chrome     • chrome     • web-javascript • Google Chrome 78.0.3904.97`

flutter run --verbose

[  +22 ms] executing: [/home/green_dome/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +213 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +3 ms] 2738a1148ba6c9a6114df62358109407c3ef2553
[        ] executing: [/home/green_dome/flutter/] git tag --contains HEAD
[ +971 ms] Exit code 0 from: git tag --contains HEAD
[        ] 1.18.0-11.1.pre
[  +48 ms] executing: [/home/green_dome/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +64 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/beta
[        ] executing: [/home/green_dome/flutter/] git ls-remote --get-url origin
[   +5 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[ +108 ms] executing: [/home/green_dome/flutter/] git rev-parse --abbrev-ref HEAD
[   +7 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] beta
[ +105 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[  +38 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +120 ms] executing: /home/green_dome/Android/Sdk/platform-tools/adb devices -l
[  +53 ms] List of devices attached
[   +5 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[  +15 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +100 ms] More than one device connected; please specify a device with the '-d <deviceId>' flag, or use '-d all' to act on all devices.
[ +361 ms] Web Server • web-server • web-javascript • Flutter Tools
[   +1 ms] Chrome     • chrome     • web-javascript • Google Chrome 78.0.3904.97
[  +14 ms] "flutter run" took 754ms.

#0      throwToolExit (package:flutter_tools/src/base/common.dart:14:3)
#1      RunCommand.validateCommand (package:flutter_tools/src/commands/run.dart:334:7)
<asynchronous suspension>
#2      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:777:11)
<asynchronous suspension>
#3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:694:33)
<asynchronous suspension>
#4      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart)
#5      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:29)
#6      _rootRun (dart:async/zone.dart:1184:13)
#7      _CustomZone.run (dart:async/zone.dart:1077:19)
#8      _runZoned (dart:async/zone.dart:1619:10)
#9      runZoned (dart:async/zone.dart:1539:10)
#10     AppContext.run (package:flutter_tools/src/base/context.dart:149:18)
#11     FlutterCommand.run (package:flutter_tools/src/runner/flutter_command.dart:684:20)
#12     CommandRunner.runCommand (package:args/command_runner.dart:197:27)
#13     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:339:21)
#14     _rootRunUnary (dart:async/zone.dart:1192:38)
#15     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#16     _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#17     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:686:45)
#18     Future._propagateToListeners (dart:async/future_impl.dart:715:32)
#19     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#20     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
#21     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:303:13)
#22     FlutterVersion.checkFlutterVersionFreshness (package:flutter_tools/src/version.dart)
#23     _rootRunUnary (dart:async/zone.dart:1192:38)
#24     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
#25     _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
#26     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:686:45)
#27     Future._propagateToListeners (dart:async/future_impl.dart:715:32)
#28     Future._completeWithValue (dart:async/future_impl.dart:526:5)
#29     Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:560:7)
#30     _rootRun (dart:async/zone.dart:1184:13)
#31     _CustomZone.run (dart:async/zone.dart:1077:19)
#32     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
#33     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
#34     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
#35     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
#36     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#37     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:169:5)`

Dependancies

dependencies:
  flutter:
    sdk: flutter
  cloud_firestore: ^0.13.6
  provider: ^4.1.2
  firebase_auth: ^0.16.1

Code

String phoneNo;    
    String smsOTP;    
    String verificationId;    
    String errorMessage = '';    
    FirebaseAuth _auth = FirebaseAuth.instance; 

    Future<void> verifyPhone() async {    
        final PhoneCodeSent smsOTPSent = (String verId, [int forceCodeResend]) {    
            this.verificationId = verId;    
            smsOTPDialog(context).then((value) {    
            print('sign in');    
            });    
        };    
        try {    
            await _auth.verifyPhoneNumber(    
                phoneNumber: this.phoneNo, // PHONE NUMBER TO SEND OTP    
                codeAutoRetrievalTimeout: (String verId) {    
                //Starts the phone number verification process for the given phone number.    
                //Either sends an SMS with a 6 digit code to the phone number specified, or sign's the user in and [verificationCompleted] is called.    
                this.verificationId = verId;    
                },    
                codeSent:    
                    smsOTPSent, // WHEN CODE SENT THEN WE OPEN DIALOG TO ENTER OTP.    
                timeout: const Duration(seconds: 20),    
                verificationCompleted: (AuthCredential phoneAuthCredential) {    
                print(phoneAuthCredential);    
                },    
                verificationFailed: (AuthException exceptio) {    
                print('${exceptio.message}');    
                });    
        } catch (e) {    
            handleError(e);    
        }    
    }    
    
    Future<bool> smsOTPDialog(BuildContext context) {    
        return showDialog(    
            context: context,    
            barrierDismissible: false,    
            builder: (BuildContext context) {    
                return new AlertDialog(    
                title: Text('Enter SMS Code'),    
                content: Container(    
                    height: 85,    
                    child: Column(children: [    
                    TextField(    
                        onChanged: (value) {    
                        this.smsOTP = value;    
                        },    
                    ),    
                    (errorMessage != ''    
                        ? Text(    
                            errorMessage,    
                            style: TextStyle(color: Colors.red),    
                            )    
                        : Container())    
                    ]),    
                ),    
                contentPadding: EdgeInsets.all(10),    
                actions: <Widget>[    
                    FlatButton(    
                    child: Text('Done'),    
                    onPressed: () {    
                        _auth.currentUser().then((user) {    
                        if (user != null) {    
                            Navigator.of(context).pop();    
                            Navigator.of(context).pushReplacementNamed('/homepage');    
                        } else {    
                            signIn();    
                        }    
                        });    
                    },    
                    )    
                ],    
                );    
        });    
    }    
    
    signIn() async {    
        try {    
            final AuthCredential credential = PhoneAuthProvider.getCredential(    
            verificationId: verificationId,    
            smsCode: smsOTP,    
            );    
            final AuthResult user = await _auth.signInWithCredential(credential);    
            final FirebaseUser currentUser = await _auth.currentUser();    
            assert(user.user.uid == currentUser.uid);    
            Navigator.of(context).pop();    
            Toast.show('logged in', context);   
        } catch (e) {    
            handleError(e);    
        }    
    }    
    
    handleError(PlatformException error) {    
        print(error);    
        switch (error.code) {    
            case 'ERROR_INVALID_VERIFICATION_CODE':    
            FocusScope.of(context).requestFocus(new FocusNode());    
            setState(() {    
                errorMessage = 'Invalid Code';    
            });    
            Navigator.of(context).pop();    
            smsOTPDialog(context).then((value) {    
                print('sign in');    
            });    
            break;    
            default:    
            setState(() {    
                errorMessage = error.message;    
            });    
    
            break;    
        }    
    }  
  @override
  Widget build(BuildContext context) {   
    return Scaffold(
      body: Center(
        child: Column(    
                mainAxisAlignment: MainAxisAlignment.center,    
                children: <Widget>[    
                Padding(    
                    padding: EdgeInsets.all(10),    
                    child: TextField(    
                    decoration: InputDecoration(    
                        hintText: 'Enter Phone Number Eg. +910000000000'),    
                    onChanged: (value) {    
                        this.phoneNo = value;    
                    },    
                    ),    
                ),    
                (errorMessage != ''    
                    ? Text(    
                        errorMessage,    
                        style: TextStyle(color: Colors.red),    
                        )    
                    : Container()),    
                SizedBox(    
                    height: 10,    
                ),    
                RaisedButton(    
                    onPressed: () {    
                    verifyPhone();    
                    },    
                    child: Text('Verify'),    
                    textColor: Colors.white,    
                    elevation: 7,    
                    color: Colors.blue,    
                )    
                ],    
            ),
      ),
    );
  }
}

@TahaTesser
Copy link

Issue is reproducible
Closing as duplicate of #2117

@firebase firebase locked and limited conversation to collaborators Jul 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested.
Projects
None yet
Development

No branches or pull requests

2 participants