Skip to content

Commit 7ef56cd

Browse files
committed
fix: renamed auth_service to auth_controller
fix: minor fixes build: updated dependencies
1 parent 9b2adf9 commit 7ef56cd

6 files changed

Lines changed: 54 additions & 50 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ class VerifyPhoneNumberScreen extends StatelessWidget {
288288
builder: (context, controller) {
289289
return Scaffold(
290290
appBar: AppBar(
291+
leadingWidth: 0,
292+
leading: const SizedBox.shrink(),
291293
title: const Text("Verify Phone Number"),
292294
actions: [
293295
if (controller.codeSent)
Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ import 'dart:async';
33
import 'package:firebase_auth/firebase_auth.dart';
44
import 'package:flutter/cupertino.dart';
55
import 'package:flutter/foundation.dart' show kIsWeb;
6+
import 'package:provider/provider.dart';
7+
8+
class FirebasePhoneAuthController extends ChangeNotifier {
9+
static FirebasePhoneAuthController of(
10+
BuildContext context, {
11+
bool listen = true,
12+
}) =>
13+
Provider.of<FirebasePhoneAuthController>(context, listen: listen);
614

7-
class FirebasePhoneAuthService extends ChangeNotifier {
815
/// {@macro timeOutDuration}
916
static const kTimeOutDuration = Duration(seconds: 60);
1017

11-
/// Firebase Auth instance using the default [FirebaseApp].
12-
FirebaseAuth? _auth = FirebaseAuth.instance;
18+
/// Firebase auth instance using the default [FirebaseApp].
19+
static final FirebaseAuth _auth = FirebaseAuth.instance;
1320

1421
/// Web confirmation result for OTP.
1522
ConfirmationResult? _webConfirmationResult;
@@ -116,54 +123,47 @@ class FirebasePhoneAuthService extends ChangeNotifier {
116123
/// [_onLoginFailed] is called with [FirebaseAuthException]
117124
/// object to handle the error.
118125
Future<bool> sendOTP() async {
119-
// this.clear();
120-
_auth ??= FirebaseAuth.instance;
121-
122-
this.codeSent = false;
123-
await Future.delayed(Duration.zero, () {
124-
notifyListeners();
125-
});
126+
codeSent = false;
127+
await Future.delayed(Duration.zero, notifyListeners);
126128

127-
verificationCompleted(AuthCredential authCredential) async {
129+
verificationCompletedCallback(AuthCredential authCredential) async {
128130
await _loginUser(authCredential: authCredential, autoVerified: true);
129131
}
130132

131-
verificationFailed(FirebaseAuthException authException) {
133+
verificationFailedCallback(FirebaseAuthException authException) {
132134
if (_onLoginFailed != null) _onLoginFailed!(authException);
133135
}
134136

135-
codeSent(
137+
codeSentCallback(
136138
String verificationId, [
137139
int? forceResendingToken,
138140
]) async {
139141
_verificationId = verificationId;
140142
_forceResendingToken = forceResendingToken;
141-
this.codeSent = true;
143+
codeSent = true;
142144
notifyListeners();
143145
_setTimer();
144146
}
145147

146-
codeAutoRetrievalTimeout(String verificationId) {
148+
codeAutoRetrievalTimeoutCallback(String verificationId) {
147149
_verificationId = verificationId;
148150
}
149151

150152
try {
151-
_auth ??= FirebaseAuth.instance;
152-
153153
if (kIsWeb) {
154-
_webConfirmationResult = await _auth!.signInWithPhoneNumber(
154+
_webConfirmationResult = await _auth.signInWithPhoneNumber(
155155
_phoneNumber!,
156156
_recaptchaVerifierForWeb,
157157
);
158-
this.codeSent = true;
158+
codeSent = true;
159159
_setTimer();
160160
} else {
161-
await _auth!.verifyPhoneNumber(
161+
await _auth.verifyPhoneNumber(
162162
phoneNumber: _phoneNumber!,
163-
verificationCompleted: verificationCompleted,
164-
verificationFailed: verificationFailed,
165-
codeSent: codeSent,
166-
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout,
163+
verificationCompleted: verificationCompletedCallback,
164+
verificationFailed: verificationFailedCallback,
165+
codeSent: codeSentCallback,
166+
codeAutoRetrievalTimeout: codeAutoRetrievalTimeoutCallback,
167167
timeout: _timeoutDuration,
168168
forceResendingToken: _forceResendingToken,
169169
);
@@ -204,8 +204,7 @@ class FirebasePhoneAuthService extends ChangeNotifier {
204204

205205
// Not on web.
206206
try {
207-
_auth ??= FirebaseAuth.instance;
208-
final authResult = await _auth!.signInWithCredential(authCredential!);
207+
final authResult = await _auth.signInWithCredential(authCredential!);
209208
if (_onLoginSuccess != null) _onLoginSuccess!(authResult, autoVerified);
210209
return true;
211210
} on FirebaseAuthException catch (e) {
@@ -227,9 +226,7 @@ class FirebasePhoneAuthService extends ChangeNotifier {
227226

228227
/// {@macro signOut}
229228
Future<void> signOut() async {
230-
// this.clear();
231-
_auth ??= FirebaseAuth.instance;
232-
await _auth!.signOut();
229+
await _auth.signOut();
233230
notifyListeners();
234231
}
235232

@@ -240,7 +237,6 @@ class FirebasePhoneAuthService extends ChangeNotifier {
240237
_recaptchaVerifierForWeb = null;
241238
}
242239
codeSent = false;
243-
_auth = null;
244240
_webConfirmationResult = null;
245241
_onLoginSuccess = null;
246242
_onLoginFailed = null;

lib/src/auth_handler.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:async';
22

33
import 'package:firebase_auth/firebase_auth.dart';
4-
import 'package:firebase_phone_auth_handler/src/auth_service.dart';
4+
import 'package:firebase_phone_auth_handler/src/auth_controller.dart';
55
import 'package:flutter/foundation.dart' show kIsWeb;
66
import 'package:flutter/material.dart';
77
import 'package:provider/provider.dart';
@@ -13,7 +13,7 @@ class FirebasePhoneAuthHandler extends StatefulWidget {
1313
required this.builder,
1414
this.onLoginFailed,
1515
this.onLoginSuccess,
16-
this.timeOutDuration = FirebasePhoneAuthService.kTimeOutDuration,
16+
this.timeOutDuration = FirebasePhoneAuthController.kTimeOutDuration,
1717
this.recaptchaVerifierForWebProvider,
1818
}) : super(key: key);
1919

@@ -50,7 +50,7 @@ class FirebasePhoneAuthHandler extends StatefulWidget {
5050
///
5151
/// Maximum allowed value is 2 minutes.
5252
///
53-
/// Defaults to [FirebasePhoneAuthService.kTimeOutDuration].
53+
/// Defaults to [FirebasePhoneAuthController.kTimeOutDuration].
5454
/// {@endtemplate}
5555
final Duration timeOutDuration;
5656

@@ -72,13 +72,13 @@ class FirebasePhoneAuthHandler extends StatefulWidget {
7272
/// The builder provides a controller which can be used to render the UI based
7373
/// on the current state.
7474
/// {@endtemplate}
75-
final Widget Function(BuildContext, FirebasePhoneAuthService) builder;
75+
final Widget Function(BuildContext, FirebasePhoneAuthController) builder;
7676

7777
/// {@template signOut}
7878
/// Signs out the current user.
7979
/// {@endtemplate}
8080
static Future<void> signOut(BuildContext context) =>
81-
Provider.of<FirebasePhoneAuthService>(context, listen: false).signOut();
81+
FirebasePhoneAuthController.of(context, listen: false).signOut();
8282

8383
@override
8484
_FirebasePhoneAuthHandlerState createState() =>
@@ -89,8 +89,7 @@ class _FirebasePhoneAuthHandlerState extends State<FirebasePhoneAuthHandler> {
8989
@override
9090
void initState() {
9191
(() async {
92-
final _con =
93-
Provider.of<FirebasePhoneAuthService>(context, listen: false);
92+
final _con = FirebasePhoneAuthController.of(context, listen: false);
9493

9594
RecaptchaVerifier? _captcha;
9695
if (widget.recaptchaVerifierForWebProvider != null) {
@@ -113,14 +112,14 @@ class _FirebasePhoneAuthHandlerState extends State<FirebasePhoneAuthHandler> {
113112
@override
114113
void dispose() {
115114
try {
116-
Provider.of<FirebasePhoneAuthService>(context, listen: false).clear();
115+
FirebasePhoneAuthController.of(context, listen: false).clear();
117116
} catch (_) {}
118117
super.dispose();
119118
}
120119

121120
@override
122121
Widget build(BuildContext context) {
123-
return Consumer<FirebasePhoneAuthService>(
122+
return Consumer<FirebasePhoneAuthController>(
124123
builder: (context, controller, _) => widget.builder(context, controller),
125124
);
126125
}

lib/src/auth_provider.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:firebase_phone_auth_handler/src/auth_service.dart';
1+
import 'package:firebase_phone_auth_handler/src/auth_controller.dart';
22
import 'package:flutter/material.dart';
33
import 'package:provider/provider.dart';
44

@@ -15,8 +15,8 @@ class FirebasePhoneAuthProvider extends StatelessWidget {
1515

1616
@override
1717
Widget build(BuildContext context) {
18-
return ChangeNotifierProvider(
19-
create: (_) => FirebasePhoneAuthService(),
18+
return ChangeNotifierProvider<FirebasePhoneAuthController>(
19+
create: (_) => FirebasePhoneAuthController(),
2020
child: child,
2121
);
2222
}

pubspec.lock

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ packages:
5656
name: firebase_auth
5757
url: "https://pub.dartlang.org"
5858
source: hosted
59-
version: "3.3.5"
59+
version: "3.3.16"
6060
firebase_auth_platform_interface:
6161
dependency: transitive
6262
description:
6363
name: firebase_auth_platform_interface
6464
url: "https://pub.dartlang.org"
6565
source: hosted
66-
version: "6.1.10"
66+
version: "6.2.4"
6767
firebase_auth_web:
6868
dependency: transitive
6969
description:
7070
name: firebase_auth_web
7171
url: "https://pub.dartlang.org"
7272
source: hosted
73-
version: "3.3.6"
73+
version: "3.3.13"
7474
firebase_core:
7575
dependency: transitive
7676
description:
@@ -84,14 +84,14 @@ packages:
8484
name: firebase_core_platform_interface
8585
url: "https://pub.dartlang.org"
8686
source: hosted
87-
version: "4.2.3"
87+
version: "4.2.5"
8888
firebase_core_web:
8989
dependency: transitive
9090
description:
9191
name: firebase_core_web
9292
url: "https://pub.dartlang.org"
9393
source: hosted
94-
version: "1.5.3"
94+
version: "1.6.2"
9595
flutter:
9696
dependency: "direct main"
9797
description: flutter
@@ -149,6 +149,13 @@ packages:
149149
url: "https://pub.dartlang.org"
150150
source: hosted
151151
version: "0.12.11"
152+
material_color_utilities:
153+
dependency: transitive
154+
description:
155+
name: material_color_utilities
156+
url: "https://pub.dartlang.org"
157+
source: hosted
158+
version: "0.1.3"
152159
meta:
153160
dependency: transitive
154161
description:
@@ -230,7 +237,7 @@ packages:
230237
name: test_api
231238
url: "https://pub.dartlang.org"
232239
source: hosted
233-
version: "0.4.3"
240+
version: "0.4.8"
234241
typed_data:
235242
dependency: transitive
236243
description:
@@ -246,5 +253,5 @@ packages:
246253
source: hosted
247254
version: "2.1.1"
248255
sdks:
249-
dart: ">=2.14.0 <3.0.0"
256+
dart: ">=2.16.0 <3.0.0"
250257
flutter: ">=1.17.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313

14-
firebase_auth: ^3.3.5
14+
firebase_auth: ^3.3.16
1515
provider: ^6.0.2
1616

1717
dev_dependencies:

0 commit comments

Comments
 (0)