julienlebren / flutter_firebase_phone_auth_riverpod Goto Github PK
View Code? Open in Web Editor NEWFlutter example project using Firebase Phone Authentication and Riverpod for state management
License: MIT License
Flutter example project using Firebase Phone Authentication and Riverpod for state management
License: MIT License
m@m-inspiron5567:~/code/flutter_firebase_phone_auth_riverpod$ git log -1
commit f951d8818361e7ce80a5703714e58af9652c03d7 (HEAD -> main, origin/main, origin/HEAD)
Author: Julien LE BREN <[email protected]>
Date: Tue May 31 09:17:00 2022 +0200
Upgraded some packages
m@m-inspiron5567:~/code/flutter_firebase_phone_auth_riverpod$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
m@m-inspiron5567:~/code/flutter_firebase_phone_auth_riverpod$ flutter pub run build_runner build --delete-conflicting-outputs
[INFO] Generating build script...
[INFO] Generating build script completed, took 379ms
[INFO] Initializing inputs
[INFO] Reading cached asset graph...
[INFO] Reading cached asset graph completed, took 73ms
[INFO] Checking for updates since last build...
[INFO] Checking for updates since last build completed, took 724ms
[INFO] Running build...
[INFO] Running build completed, took 22ms
[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 37ms
[SEVERE] freezed:freezed on lib/state/auth_state.dart (cached):
An error `FormatterException` occurred while formatting the generated source for
`package:flutter_firebase_phone_auth_riverpod/state/auth_state.dart`
which was output to
`lib/state/auth_state.freezed.dart`.
This may indicate an issue in the generator, the input source code, or in the
source formatter.
Could not format because the source could not be parsed:
line 21, column 147 of .: Expected to find ')'.
╷
21 │ @optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() initializing,required TResult Function( CountryWithPhoneCode* country) ready,required TResult Function( String* errorText) error,}) => throw _privateConstructorUsedError;
│ ^
╵
line 21, column 198 of .: Expected to find ')'.
╷
21 │ @optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() initializing,required TResult Function( CountryWithPhoneCode* country) ready,required TResult Function( String* errorText) error,}) => throw _privateConstructorUsedError;
│ ^
╵
line 22, column 137 of .: Expected to find ')'.
╷
22 │ @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult Function()? initializing,TResult Function( CountryWithPhoneCode* country)? ready,TResult Function( String* errorText)? error,}) => throw _privateConstructorUsedError;
│ ^
╵
line 22, column 180 of .: Expected to find ')'.
╷
22 │ @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult Function()? initializing,TResult Function( CountryWithPhoneCode* country)? ready,TResult Function( String* errorText)? error,}) => throw _privateConstructorUsedError;
│ ^
╵
line 23, column 135 of .: Expected to find ')'.
╷
23 │ @optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function()? initializing,TResult Function( CountryWithPhoneCode* country)? ready,TResult Function( String* errorText)? error,required TResult orElse(),}) => throw _privateConstructorUsedError;
│ ^
╵
line 23, column 178 of .: Expected to find ')'.
╷
23 │ @optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function()? initializing,TResult Function( CountryWithPhoneCode* country)? ready,TResult Function( String* errorText)? error,required TResult orElse(),}) => throw _privateConstructorUsedError;
│ ^
╵
line 100, column 147 of .: Expected to find ')'.
╷
100 │ @optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() initializing,required TResult Function( CountryWithPhoneCode* country) ready,required TResult Function( String* errorText) error,}) {
│ ^
╵
line 100, column 198 of .: Expected to find ')'.
╷
100 │ @optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() initializing,required TResult Function( CountryWithPhoneCode* country) ready,required TResult Function( String* errorText) error,}) {
│ ^
╵
line 104, column 137 of .: Expected to find ')'.
╷
104 │ @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult Function()? initializing,TResult Function( CountryWithPhoneCode* country)? ready,TResult Function( String* errorText)? error,}) {
│ ^
╵
line 104, column 180 of .: Expected to find ')'.
╷
104 │ @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult Function()? initializing,TResult Function( CountryWithPhoneCode* country)? ready,TResult Function( String* errorText)? error,}) {
│ ^
╵
(40 more errors...)
[SEVERE] freezed:freezed on lib/state/sign_in_state.dart (cached):
An error `FormatterException` occurred while formatting the generated source for
`package:flutter_firebase_phone_auth_riverpod/state/sign_in_state.dart`
which was output to
`lib/state/sign_in_state.freezed.dart`.
This may indicate an issue in the generator, the input source code, or in the
source formatter.
Could not format because the source could not be parsed:
line 21, column 242 of .: Expected to find ')'.
╷
21 │ @optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() notValid,required TResult Function() canSubmit,required TResult Function() loading,required TResult Function() success,required TResult Function( String* errorText) error,}) => throw _privateConstructorUsedError;
│ ^
╵
line 22, column 208 of .: Expected to find ')'.
╷
22 │ @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult Function()? notValid,TResult Function()? canSubmit,TResult Function()? loading,TResult Function()? success,TResult Function( String* errorText)? error,}) => throw _privateConstructorUsedError;
│ ^
╵
line 23, column 206 of .: Expected to find ')'.
╷
23 │ @optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function()? notValid,TResult Function()? canSubmit,TResult Function()? loading,TResult Function()? success,TResult Function( String* errorText)? error,required TResult orElse(),}) => throw _privateConstructorUsedError;
│ ^
╵
line 107, column 242 of .: Expected to find ')'.
╷
107 │ @optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() notValid,required TResult Function() canSubmit,required TResult Function() loading,required TResult Function() success,required TResult Function( String* errorText) error,}) {
│ ^
╵
line 111, column 208 of .: Expected to find ')'.
╷
111 │ @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult Function()? notValid,TResult Function()? canSubmit,TResult Function()? loading,TResult Function()? success,TResult Function( String* errorText)? error,}) {
│ ^
╵
line 115, column 206 of .: Expected to find ')'.
╷
115 │ @optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function()? notValid,TResult Function()? canSubmit,TResult Function()? loading,TResult Function()? success,TResult Function( String* errorText)? error,required TResult orElse(),}) {
│ ^
╵
line 205, column 242 of .: Expected to find ')'.
╷
205 │ @optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() notValid,required TResult Function() canSubmit,required TResult Function() loading,required TResult Function() success,required TResult Function( String* errorText) error,}) {
│ ^
╵
line 209, column 208 of .: Expected to find ')'.
╷
209 │ @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult Function()? notValid,TResult Function()? canSubmit,TResult Function()? loading,TResult Function()? success,TResult Function( String* errorText)? error,}) {
│ ^
╵
line 213, column 206 of .: Expected to find ')'.
╷
213 │ @optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function()? notValid,TResult Function()? canSubmit,TResult Function()? loading,TResult Function()? success,TResult Function( String* errorText)? error,required TResult orElse(),}) {
│ ^
╵
line 303, column 242 of .: Expected to find ')'.
╷
303 │ @optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function() notValid,required TResult Function() canSubmit,required TResult Function() loading,required TResult Function() success,required TResult Function( String* errorText) error,}) {
│ ^
╵
(21 more errors...)
[SEVERE] Failed after 81ms
pub finished with exit code 1
Hey @julienlebren
Thanks for your work, i will replace my implementation by yours; mine is messy :)
Could you share also how do you handle the user/profile creation (not the firebase auth one).
Im using StartupPage
too, and im doing there kind of getorCreateUser
; but it's an async process, and im getting some of intermediate black screen (while async request is running)...
Thank you,
Nelson
Hi there,
great work with this riverpod phone auth example, thank you for that :)
There is a problem though. I am using latest version of Flutter SDK and this is my pubspec.yaml file:
name: flutter_firebase_phone_auth_riverpod
description: Using Riverpod to handle Firebase Phone Authentication
publish_to: "none"
version: 1.2.0
environment:
sdk: '>=2.18.0-159.0.dev <3.0.0'
dependencies:
cupertino_icons: ^1.0.4
firebase_auth: ^3.3.19
firebase_core: ^1.17.1
flutter:
sdk: flutter
flutter_libphonenumber: 1.1.0
flutter_riverpod: ^1.0.4
freezed_annotation: ^2.0.3
pinput: ^2.2.9
dev_dependencies:
build_runner: ^2.1.11
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter
freezed: ^2.0.3+1
flutter:
uses-material-design: true
assets:
- assets/
When i try to run your example app, it outputs quite a lot of errors, seems like because of null-safety. Could you take a look and fix it perhaps, so we would have a working example?
flutter run
Using hardware rendering with device sdk gphone x86. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on sdk gphone x86 in debug mode...
lib/app/common_widgets/error_page.dart:5:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/common_widgets/error_page.dart:6:10: Error: The parameter 'message' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.message,
^^^^^^^
lib/app/common_widgets/buttons.dart:5:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/common_widgets/buttons.dart:6:10: Error: The parameter 'title' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.title,
^^^^^
lib/app/common_widgets/buttons.dart:7:10: Error: The parameter 'onPressed' can't have a value of 'null' because of its type 'void Function()', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.onPressed,
^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:71:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/sign_in/sign_in_phone_page.dart:74:10: Error: The parameter 'errorText' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.errorText,
^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:75:10: Error: The parameter 'phoneCode' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.phoneCode,
^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:76:10: Error: The parameter 'phonePlaceholder' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.phonePlaceholder,
^^^^^^^^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:77:10: Error: The parameter 'formatter' can't have a value of 'null' because of its type 'LibPhonenumberTextFormatter', but the implicit default value is 'null'.
- 'LibPhonenumberTextFormatter' is from 'package:flutter_libphonenumber/src/input_formatter/input_formatter.dart' ('../../.pub-cache/hosted/pub.dartlang.org/flutter_libphonenumber-1.1.0/lib/src/input_formatter/input_formatter.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.formatter,
^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:78:10: Error: The parameter 'onSubmit' can't have a value of 'null' because of its type 'dynamic Function()', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.onSubmit,
^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:64:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/sign_in/sign_in_verification_page.dart:65:10: Error: The parameter 'phoneNumber' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.phoneNumber,
^^^^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:68:10: Error: The parameter 'errorText' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.errorText,
^^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:69:10: Error: The parameter 'delayBeforeNewCode' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.delayBeforeNewCode,
^^^^^^^^^^^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:70:10: Error: The parameter 'resendCode' can't have a value of 'null' because of its type 'dynamic Function()', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.resendCode,
^^^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:71:10: Error: The parameter 'verifyCode' can't have a value of 'null' because of its type 'dynamic Function(String)', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.verifyCode,
^^^^^^^^^^
lib/app/common_widgets/error_text.dart:5:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/common_widgets/error_text.dart:6:10: Error: The parameter 'message' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.message,
^^^^^^^
lib/app/sign_in/sign_in_phone_model.dart:8:10: Error: The parameter 'authService' can't have a value of 'null' because of its type 'AuthService', but the implicit default value is 'null'.
- 'AuthService' is from 'package:flutter_firebase_phone_auth_riverpod/services/auth_service.dart' ('lib/services/auth_service.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.authService,
^^^^^^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:10:10: Error: The parameter 'authService' can't have a value of 'null' because of its type 'AuthService', but the implicit default value is 'null'.
- 'AuthService' is from 'package:flutter_firebase_phone_auth_riverpod/services/auth_service.dart' ('lib/services/auth_service.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.authService,
^^^^^^^^^^^
lib/app/routing/app_router.dart:39:16: Error: The value 'null' can't be returned from a function with return type 'Route<dynamic>' because 'Route<dynamic>' is not nullable.
- 'Route' is from 'package:flutter/src/widgets/navigator.dart' ('../../development/flutter/packages/flutter/lib/src/widgets/navigator.dart').
return null;
^
lib/app/sign_in/sign_in_phone_page.dart:24:19: Error: The value 'null' can't be returned from a function with return type 'CountryWithPhoneCode' because 'CountryWithPhoneCode' is not nullable.
- 'CountryWithPhoneCode' is from 'package:flutter_libphonenumber/src/country_data.dart' ('../../.pub-cache/hosted/pub.dartlang.org/flutter_libphonenumber-1.1.0/lib/src/country_data.dart').
orElse: () => null,
^
lib/app/sign_in/sign_in_phone_page.dart:49:12: Error: Method 'replaceAll' cannot be called on 'String?' because it is potentially null.
Try calling using ?. instead.
.replaceAll('+${selectedCountry.phoneCode} ', ''),
^^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:63:23: Error: The value 'null' can't be returned from a function with return type 'String' because 'String' is not nullable.
orElse: () => null,
^
lib/app/sign_in/sign_in_phone_page.dart:162:58: Error: The argument type 'Color?' can't be assigned to the parameter type 'Color' because 'Color?' is nullable and 'Color' isn't.
- 'Color' is from 'dart:ui'.
BorderSide(color: Colors.grey[300], width: 1.0),
^
lib/app/sign_in/sign_in_phone_page.dart:176:45: Error: The argument type 'dynamic Function()?' can't be assigned to the parameter type 'void Function()' because 'dynamic Function()?' is nullable and 'void Function()' isn't.
onPressed: widget.canSubmit ? widget.onSubmit : null,
^
lib/app/sign_in/sign_in_verification_page.dart:56:23: Error: The value 'null' can't be returned from a function with return type 'String' because 'String' is not nullable.
orElse: () => null,
^
lib/app/sign_in/sign_in_verification_page.dart:102:46: Error: The argument type 'Color?' can't be assigned to the parameter type 'Color' because 'Color?' is nullable and 'Color' isn't.
- 'Color' is from 'dart:ui'.
border: Border.all(color: Colors.grey[300]),
^
lib/app/sign_in/sign_in_verification_page.dart:147:53: Error: Property 'length' cannot be accessed on 'String?' because it is potentially null.
Try accessing using ?. instead.
if (widget.errorText == null && s.length == 6)
^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:148:39: Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
widget.verifyCode(s);
^
lib/services/auth_service.dart:19:52: Error: A value of type 'Stream<User?>' can't be returned from a function with return type 'Stream<User>' because 'User?' is nullable and 'User' isn't.
- 'Stream' is from 'dart:async'.
- 'User' is from 'package:firebase_auth/firebase_auth.dart' ('../../.pub-cache/hosted/pub.dartlang.org/firebase_auth-3.3.19/lib/firebase_auth.dart').
Stream<User> authStateChanges() => _firebaseAuth.authStateChanges();
^
lib/services/auth_service.dart:30:14: Error: Method 'toLowerCase' cannot be called on 'String?' because it is potentially null.
Try calling using ?. instead.
.toLowerCase()
^^^^^^^^^^^
lib/services/auth_service.dart:31:38: Error: Method 'toLowerCase' cannot be called on 'String?' because it is potentially null.
Try calling using ?. instead.
.compareTo(b.countryName.toLowerCase());
^^^^^^^^^^^
package:flutter_firebase_phone_auth_riverpod/services/auth_service.dart: Error: The parameter 'resendToken' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
lib/services/auth_service.dart:77:17: Error: The argument type 'void Function(String, [int])' can't be assigned to the parameter type 'void Function(String, int?)' because 'int?' is nullable and 'int' isn't.
codeSent: (String verificationId, [int resendToken]) {
^
lib/app/sign_in/sign_in_phone_model.dart:28:14: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
if (!e.message.contains('parse')) {
^^^^^^^
lib/app/sign_in/sign_in_phone_model.dart:29:37: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
state = SignInState.error(e.message);
^^^^^^^
lib/app/sign_in/sign_in_phone_model.dart:43:35: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
state = SignInState.error(e.message);
^^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:51:35: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
state = SignInState.error(e.message);
^^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:62:13: Error: The getter 'code' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'code'.
if (e.code == "invalid-verification-code") {
^^^^
lib/app/sign_in/sign_in_verification_model.dart:65:37: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
state = SignInState.error(e.message);
^^^^^^^
lib/services/auth_service.dart:13:16: Error: Field '_firebaseAuth' should be initialized because its type 'FirebaseAuth' doesn't allow null.
- 'FirebaseAuth' is from 'package:firebase_auth/firebase_auth.dart' ('../../.pub-cache/hosted/pub.dartlang.org/firebase_auth-3.3.19/lib/firebase_auth.dart').
FirebaseAuth _firebaseAuth;
^^^^^^^^^^^^^
lib/services/auth_service.dart:14:24: Error: Field '_selectedCountry' should be initialized because its type 'CountryWithPhoneCode' doesn't allow null.
- 'CountryWithPhoneCode' is from 'package:flutter_libphonenumber/src/country_data.dart' ('../../.pub-cache/hosted/pub.dartlang.org/flutter_libphonenumber-1.1.0/lib/src/country_data.dart').
CountryWithPhoneCode _selectedCountry;
^^^^^^^^^^^^^^^^
lib/services/auth_service.dart:15:7: Error: Field '_phoneNumber' should be initialized because its type 'Map<dynamic, dynamic>' doesn't allow null.
- 'Map' is from 'dart:core'.
Map _phoneNumber;
^^^^^^^^^^^^
lib/services/auth_service.dart:16:10: Error: Field '_verificationId' should be initialized because its type 'String' doesn't allow null.
String _verificationId;
^^^^^^^^^^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:18:9: Error: Field '_timer' should be initialized because its type 'Timer' doesn't allow null.
- 'Timer' is from 'dart:async'.
Timer _timer;
^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:20:7: Error: Field '_countdown' should be initialized because its type 'int' doesn't allow null.
int _countdown;
^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script '/home/dino/development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1159
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/dino/development/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Running Gradle task 'assembleDebug'... 8.6s
Exception: Gradle task assembleDebug failed with exit code 1
Then i have also tried to run it with null safety disabled, but it produced errors as well.
flutter run --no-sound-null-safety
Using hardware rendering with device sdk gphone x86. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on sdk gphone x86 in debug mode...
lib/app/common_widgets/error_page.dart:5:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/common_widgets/error_page.dart:6:10: Error: The parameter 'message' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.message,
^^^^^^^
lib/app/common_widgets/buttons.dart:5:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/common_widgets/buttons.dart:6:10: Error: The parameter 'title' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.title,
^^^^^
lib/app/common_widgets/buttons.dart:7:10: Error: The parameter 'onPressed' can't have a value of 'null' because of its type 'void Function()', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.onPressed,
^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:71:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/sign_in/sign_in_phone_page.dart:74:10: Error: The parameter 'errorText' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.errorText,
^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:75:10: Error: The parameter 'phoneCode' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.phoneCode,
^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:76:10: Error: The parameter 'phonePlaceholder' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.phonePlaceholder,
^^^^^^^^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:77:10: Error: The parameter 'formatter' can't have a value of 'null' because of its type 'LibPhonenumberTextFormatter', but the implicit default value is 'null'.
- 'LibPhonenumberTextFormatter' is from 'package:flutter_libphonenumber/src/input_formatter/input_formatter.dart' ('../../.pub-cache/hosted/pub.dartlang.org/flutter_libphonenumber-1.1.0/lib/src/input_formatter/input_formatter.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.formatter,
^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:78:10: Error: The parameter 'onSubmit' can't have a value of 'null' because of its type 'dynamic Function()', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.onSubmit,
^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:64:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/sign_in/sign_in_verification_page.dart:65:10: Error: The parameter 'phoneNumber' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.phoneNumber,
^^^^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:68:10: Error: The parameter 'errorText' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.errorText,
^^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:69:10: Error: The parameter 'delayBeforeNewCode' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.delayBeforeNewCode,
^^^^^^^^^^^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:70:10: Error: The parameter 'resendCode' can't have a value of 'null' because of its type 'dynamic Function()', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.resendCode,
^^^^^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:71:10: Error: The parameter 'verifyCode' can't have a value of 'null' because of its type 'dynamic Function(String)', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.verifyCode,
^^^^^^^^^^
lib/app/common_widgets/error_text.dart:5:9: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'.
- 'Key' is from 'package:flutter/src/foundation/key.dart' ('../../development/flutter/packages/flutter/lib/src/foundation/key.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
Key key,
^^^
lib/app/common_widgets/error_text.dart:6:10: Error: The parameter 'message' can't have a value of 'null' because of its type 'String', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.message,
^^^^^^^
lib/app/sign_in/sign_in_phone_model.dart:8:10: Error: The parameter 'authService' can't have a value of 'null' because of its type 'AuthService', but the implicit default value is 'null'.
- 'AuthService' is from 'package:flutter_firebase_phone_auth_riverpod/services/auth_service.dart' ('lib/services/auth_service.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.authService,
^^^^^^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:10:10: Error: The parameter 'authService' can't have a value of 'null' because of its type 'AuthService', but the implicit default value is 'null'.
- 'AuthService' is from 'package:flutter_firebase_phone_auth_riverpod/services/auth_service.dart' ('lib/services/auth_service.dart').
Try adding either an explicit non-'null' default value or the 'required' modifier.
this.authService,
^^^^^^^^^^^
lib/app/routing/app_router.dart:39:16: Error: The value 'null' can't be returned from a function with return type 'Route<dynamic>' because 'Route<dynamic>' is not nullable.
- 'Route' is from 'package:flutter/src/widgets/navigator.dart' ('../../development/flutter/packages/flutter/lib/src/widgets/navigator.dart').
return null;
^
lib/app/sign_in/sign_in_phone_page.dart:24:19: Error: The value 'null' can't be returned from a function with return type 'CountryWithPhoneCode' because 'CountryWithPhoneCode' is not nullable.
- 'CountryWithPhoneCode' is from 'package:flutter_libphonenumber/src/country_data.dart' ('../../.pub-cache/hosted/pub.dartlang.org/flutter_libphonenumber-1.1.0/lib/src/country_data.dart').
orElse: () => null,
^
lib/app/sign_in/sign_in_phone_page.dart:49:12: Error: Method 'replaceAll' cannot be called on 'String?' because it is potentially null.
Try calling using ?. instead.
.replaceAll('+${selectedCountry.phoneCode} ', ''),
^^^^^^^^^^
lib/app/sign_in/sign_in_phone_page.dart:63:23: Error: The value 'null' can't be returned from a function with return type 'String' because 'String' is not nullable.
orElse: () => null,
^
lib/app/sign_in/sign_in_phone_page.dart:162:58: Error: The argument type 'Color?' can't be assigned to the parameter type 'Color' because 'Color?' is nullable and 'Color' isn't.
- 'Color' is from 'dart:ui'.
BorderSide(color: Colors.grey[300], width: 1.0),
^
lib/app/sign_in/sign_in_phone_page.dart:176:45: Error: The argument type 'dynamic Function()?' can't be assigned to the parameter type 'void Function()' because 'dynamic Function()?' is nullable and 'void Function()' isn't.
onPressed: widget.canSubmit ? widget.onSubmit : null,
^
lib/app/sign_in/sign_in_verification_page.dart:56:23: Error: The value 'null' can't be returned from a function with return type 'String' because 'String' is not nullable.
orElse: () => null,
^
lib/app/sign_in/sign_in_verification_page.dart:102:46: Error: The argument type 'Color?' can't be assigned to the parameter type 'Color' because 'Color?' is nullable and 'Color' isn't.
- 'Color' is from 'dart:ui'.
border: Border.all(color: Colors.grey[300]),
^
lib/app/sign_in/sign_in_verification_page.dart:147:53: Error: Property 'length' cannot be accessed on 'String?' because it is potentially null.
Try accessing using ?. instead.
if (widget.errorText == null && s.length == 6)
^^^^^^
lib/app/sign_in/sign_in_verification_page.dart:148:39: Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
widget.verifyCode(s);
^
lib/services/auth_service.dart:19:52: Error: A value of type 'Stream<User?>' can't be returned from a function with return type 'Stream<User>' because 'User?' is nullable and 'User' isn't.
- 'Stream' is from 'dart:async'.
- 'User' is from 'package:firebase_auth/firebase_auth.dart' ('../../.pub-cache/hosted/pub.dartlang.org/firebase_auth-3.3.19/lib/firebase_auth.dart').
Stream<User> authStateChanges() => _firebaseAuth.authStateChanges();
^
lib/services/auth_service.dart:30:14: Error: Method 'toLowerCase' cannot be called on 'String?' because it is potentially null.
Try calling using ?. instead.
.toLowerCase()
^^^^^^^^^^^
lib/services/auth_service.dart:31:38: Error: Method 'toLowerCase' cannot be called on 'String?' because it is potentially null.
Try calling using ?. instead.
.compareTo(b.countryName.toLowerCase());
^^^^^^^^^^^
package:flutter_firebase_phone_auth_riverpod/services/auth_service.dart: Error: The parameter 'resendToken' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.
lib/services/auth_service.dart:77:17: Error: The argument type 'void Function(String, [int])' can't be assigned to the parameter type 'void Function(String, int?)' because 'int?' is nullable and 'int' isn't.
codeSent: (String verificationId, [int resendToken]) {
^
lib/app/sign_in/sign_in_phone_model.dart:28:14: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
if (!e.message.contains('parse')) {
^^^^^^^
lib/app/sign_in/sign_in_phone_model.dart:29:37: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
state = SignInState.error(e.message);
^^^^^^^
lib/app/sign_in/sign_in_phone_model.dart:43:35: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
state = SignInState.error(e.message);
^^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:51:35: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
state = SignInState.error(e.message);
^^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:62:13: Error: The getter 'code' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'code'.
if (e.code == "invalid-verification-code") {
^^^^
lib/app/sign_in/sign_in_verification_model.dart:65:37: Error: The getter 'message' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
state = SignInState.error(e.message);
^^^^^^^
lib/services/auth_service.dart:13:16: Error: Field '_firebaseAuth' should be initialized because its type 'FirebaseAuth' doesn't allow null.
- 'FirebaseAuth' is from 'package:firebase_auth/firebase_auth.dart' ('../../.pub-cache/hosted/pub.dartlang.org/firebase_auth-3.3.19/lib/firebase_auth.dart').
FirebaseAuth _firebaseAuth;
^^^^^^^^^^^^^
lib/services/auth_service.dart:14:24: Error: Field '_selectedCountry' should be initialized because its type 'CountryWithPhoneCode' doesn't allow null.
- 'CountryWithPhoneCode' is from 'package:flutter_libphonenumber/src/country_data.dart' ('../../.pub-cache/hosted/pub.dartlang.org/flutter_libphonenumber-1.1.0/lib/src/country_data.dart').
CountryWithPhoneCode _selectedCountry;
^^^^^^^^^^^^^^^^
lib/services/auth_service.dart:15:7: Error: Field '_phoneNumber' should be initialized because its type 'Map<dynamic, dynamic>' doesn't allow null.
- 'Map' is from 'dart:core'.
Map _phoneNumber;
^^^^^^^^^^^^
lib/services/auth_service.dart:16:10: Error: Field '_verificationId' should be initialized because its type 'String' doesn't allow null.
String _verificationId;
^^^^^^^^^^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:18:9: Error: Field '_timer' should be initialized because its type 'Timer' doesn't allow null.
- 'Timer' is from 'dart:async'.
Timer _timer;
^^^^^^
lib/app/sign_in/sign_in_verification_model.dart:20:7: Error: Field '_countdown' should be initialized because its type 'int' doesn't allow null.
int _countdown;
^^^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script '/home/dino/development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1159
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/dino/development/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 7s
Running Gradle task 'assembleDebug'... 8.4s
Exception: Gradle task assembleDebug failed with exit code 1
Kind regards,
Neon
I have this 2 methods in flutter for firebase phone authentication:
Future<void> verifyPhone(Function() completion) async {
_logger.i("start verifyPhone");
await _firebaseAuth.verifyPhoneNumber(
phoneNumber: _phoneNumber?['e164'],
verificationCompleted: (AuthCredential credential) async {
_logger.i("verifyPhone completed");
await _firebaseAuth.signInWithCredential(credential);
},
verificationFailed: (FirebaseException e) {
_logger.e("verifyPhone failed", error: e.code);
throw e;
},
codeSent: (String verificationId, int? resendToken) {
_logger.i("verifyPhone codeSent");
_verificationId = verificationId;
completion();
},
codeAutoRetrievalTimeout: (String verificationId) {
_logger.i("verifyPhone codeAutoRetrievalTimeout");
_verificationId = verificationId;
completion();
}
timeout: const Duration(seconds: 120),
);
}
verifyPhone
is then called by
Future<void> callVerifyPhone() async {
state = const SignInState.loading();
try {
await ref.read(authServiceProvider.notifier).verifyPhone(() {
state = const SignInState.success();
_analytics.logEvent(
name: 'verifyPhone',
parameters: {
"phone_number": ref.read(authServiceProvider).formattedPhoneNumber,
},
);
});
} catch (e) {
FirebaseCrashlytics.instance.recordError(
e,
null,
information: ['verifyPhone failed'],
);
_logger.e('verifyPhone failed: $e', error: e);
state = const SignInState.error(SignInError.error);
}
}
the exception thrown within verificationFailed never reaches the callVerifyPhone catch block.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.