Skip to content

Commit f1fbe0b

Browse files
committed
refactor: Riverpod notifiers fields are now private.
1 parent 4561df1 commit f1fbe0b

26 files changed

+315
-195
lines changed

lib/main.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,11 @@ class _RouteWidgetState extends ConsumerState<_RouteWidget> {
263263
);
264264
}
265265
ref.listenManual(
266-
totpLimitExceededProvider,
266+
totpLimitProvider,
267267
(previous, next) async {
268-
if (next.valueOrNull != true) {
269-
return;
268+
if (next.valueOrNull?.isExceeded == true && mounted) {
269+
TotpLimitDialog.showAndBlock(context);
270270
}
271-
TotpLimitDialog.showAndBlock(context);
272271
},
273272
fireImmediately: true,
274273
);
@@ -315,7 +314,7 @@ class _RouteWidgetState extends ConsumerState<_RouteWidget> {
315314
String? mode = link.queryParameters['mode'];
316315
switch (mode) {
317316
case 'signIn':
318-
EmailLinkAuthenticationProvider emailAuthenticationProvider = ref.read(emailLinkAuthenticationProvider.notifier);
317+
EmailLinkAuthenticationProvider emailAuthenticationProvider = ref.read(emailLinkAuthenticationProvider);
319318
if (!(await emailAuthenticationProvider.isWaitingForConfirmation())) {
320319
return;
321320
}

lib/model/app_unlock/method.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class MasterPasswordAppUnlockMethod extends AppUnlockMethod {
9090
return const ResultCancelled();
9191
}
9292

93-
Result<bool> passwordCheckResult = await ref.read(passwordVerificationProvider.notifier).isPasswordValid(password);
93+
Result<bool> passwordCheckResult = await (await ref.read(passwordVerificationProvider.future)).isPasswordValid(password);
9494
if (passwordCheckResult is! ResultSuccess || !(passwordCheckResult as ResultSuccess<bool>).value) {
9595
return ResultError();
9696
}

lib/model/authentication/providers/apple.dart

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ import 'package:open_authenticator/utils/validation/sign_in/apple.dart';
99
import 'package:open_authenticator/utils/validation/sign_in/oauth2.dart';
1010

1111
/// The Apple authentication provider.
12-
final appleAuthenticationProvider = NotifierProvider<AppleAuthenticationProvider, FirebaseAuthenticationState>(AppleAuthenticationProvider.new);
12+
final appleAuthenticationProvider = Provider<AppleAuthenticationProvider>((ref) => AppleAuthenticationProvider());
13+
14+
/// The Apple authentication state provider.
15+
final appleAuthenticationStateProvider = NotifierProvider<FirebaseAuthenticationProviderNotifier, FirebaseAuthenticationState>(
16+
() => FirebaseAuthenticationProviderNotifier(appleAuthenticationProvider),
17+
);
1318

1419
/// The provider that allows to sign-in using Apple.
1520
class AppleAuthenticationProvider extends FirebaseAuthenticationProvider with LinkProvider, FallbackAuthenticationProvider<AppleSignIn> {
1621
/// Creates a new Apple authentication provider instance.
17-
AppleAuthenticationProvider()
22+
const AppleAuthenticationProvider()
1823
: super(
1924
availablePlatforms: const [
2025
Platform.android,
@@ -29,20 +34,20 @@ class AppleAuthenticationProvider extends FirebaseAuthenticationProvider with Li
2934

3035
@override
3136
AppleAuthMethod createDefaultAuthMethod(BuildContext context, {List<String> scopes = const []}) => AppleAuthMethod.defaultMethod(
32-
scopes: scopes,
33-
customParameters: {
34-
'locale': TranslationProvider.of(context).flutterLocale.languageCode,
35-
},
36-
);
37+
scopes: scopes,
38+
customParameters: {
39+
'locale': TranslationProvider.of(context).flutterLocale.languageCode,
40+
},
41+
);
3742

3843
@override
3944
AppleAuthMethod createRestAuthMethod(BuildContext context, OAuth2Response response) => AppleAuthMethod.rest(
40-
idToken: response.idToken,
41-
nonce: response.nonce,
42-
);
45+
idToken: response.idToken,
46+
nonce: response.nonce,
47+
);
4348

4449
@override
4550
AppleSignIn createFallbackAuthProvider() => AppleSignIn(
46-
clientId: 'app.openauthenticator.service',
47-
);
51+
clientId: 'app.openauthenticator.service',
52+
);
4853
}

lib/model/authentication/providers/email_link.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,29 @@ import 'package:open_authenticator/widgets/waiting_overlay.dart';
1616
import 'package:package_info_plus/package_info_plus.dart';
1717

1818
/// The email link authentication provider.
19-
final emailLinkAuthenticationProvider = NotifierProvider<EmailLinkAuthenticationProvider, FirebaseAuthenticationState>(EmailLinkAuthenticationProvider.new);
19+
final emailLinkAuthenticationProvider = Provider<EmailLinkAuthenticationProvider>(
20+
(ref) => EmailLinkAuthenticationProvider(
21+
ref: ref,
22+
),
23+
);
24+
25+
/// The email link authentication state provider.
26+
final emailLinkAuthenticationStateProvider = NotifierProvider<FirebaseAuthenticationProviderNotifier, FirebaseAuthenticationState>(
27+
() => FirebaseAuthenticationProviderNotifier(emailLinkAuthenticationProvider),
28+
);
2029

2130
/// The provider that allows to sign-in using an email link.
2231
class EmailLinkAuthenticationProvider extends FirebaseAuthenticationProvider with ConfirmationProvider<String> {
2332
/// The preferences key where the email is temporally stored.
2433
static const String _kFirebaseAuthenticationEmailKey = 'firebaseAuthenticationEmail';
2534

35+
/// The Riverpod ref instance.
36+
final Ref ref;
37+
2638
/// Creates a new email link authentication provider instance.
27-
EmailLinkAuthenticationProvider()
28-
: super(
39+
const EmailLinkAuthenticationProvider({
40+
required this.ref,
41+
}) : super(
2942
availablePlatforms: const [
3043
Platform.android,
3144
Platform.iOS,
@@ -122,7 +135,7 @@ class EmailLinkAuthenticationProvider extends FirebaseAuthenticationProvider wit
122135
}
123136
SharedPreferencesWithPrefix preferences = await ref.read(sharedPreferencesProvider.future);
124137
await preferences.setString(_kFirebaseAuthenticationEmailKey, email);
125-
ref.invalidateSelf();
138+
ref.invalidate(emailLinkAuthenticationStateProvider);
126139
return ResultSuccess(
127140
value: AuthenticationObject(
128141
email: email,
@@ -145,7 +158,7 @@ class EmailLinkAuthenticationProvider extends FirebaseAuthenticationProvider wit
145158
try {
146159
SharedPreferencesWithPrefix preferences = await ref.read(sharedPreferencesProvider.future);
147160
await preferences.remove(_kFirebaseAuthenticationEmailKey);
148-
ref.invalidateSelf();
161+
ref.invalidate(emailLinkAuthenticationStateProvider);
149162
return const ResultSuccess();
150163
} catch (ex, stacktrace) {
151164
return ResultError(
@@ -187,7 +200,7 @@ class EmailLinkAuthenticationProvider extends FirebaseAuthenticationProvider wit
187200
future: FirebaseAuth.instance.signInWith(method),
188201
);
189202
await preferences.remove(_kFirebaseAuthenticationEmailKey);
190-
ref.invalidateSelf();
203+
ref.invalidate(emailLinkAuthenticationStateProvider);
191204
return ResultSuccess(
192205
value: AuthenticationObject(
193206
email: signInResult.email,

lib/model/authentication/providers/github.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ import 'package:open_authenticator/utils/validation/sign_in/github.dart';
99
import 'package:open_authenticator/utils/validation/sign_in/oauth2.dart';
1010

1111
/// The Github authentication provider.
12-
final githubAuthenticationProvider = NotifierProvider<GithubAuthenticationProvider, FirebaseAuthenticationState>(GithubAuthenticationProvider.new);
12+
final githubAuthenticationProvider = Provider<GithubAuthenticationProvider>((ref) => GithubAuthenticationProvider());
13+
14+
/// The Github authentication provider.
15+
final githubAuthenticationStateProvider = NotifierProvider<FirebaseAuthenticationProviderNotifier, FirebaseAuthenticationState>(
16+
() => FirebaseAuthenticationProviderNotifier(githubAuthenticationProvider),
17+
);
1318

1419
/// The provider that allows to sign-in using Github.
1520
class GithubAuthenticationProvider extends FirebaseAuthenticationProvider with LinkProvider, FallbackAuthenticationProvider<GithubSignIn> {
1621
/// Creates a new Github authentication provider instance.
17-
GithubAuthenticationProvider()
22+
const GithubAuthenticationProvider()
1823
: super(
1924
availablePlatforms: const [
2025
Platform.android,

lib/model/authentication/providers/google.dart

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_riverpod/flutter_riverpod.dart';
33
import 'package:open_authenticator/app.dart';
4+
import 'package:open_authenticator/model/authentication/firebase_authentication.dart';
45
import 'package:open_authenticator/model/authentication/providers/provider.dart';
56
import 'package:open_authenticator/model/authentication/state.dart';
67
import 'package:open_authenticator/utils/firebase_auth/firebase_auth.dart';
@@ -9,13 +10,27 @@ import 'package:open_authenticator/utils/validation/sign_in/google.dart';
910
import 'package:open_authenticator/utils/validation/sign_in/oauth2.dart';
1011

1112
/// The Google authentication provider.
12-
final googleAuthenticationProvider = NotifierProvider<GoogleAuthenticationProvider, FirebaseAuthenticationState>(GoogleAuthenticationProvider.new);
13+
final googleAuthenticationProvider = Provider<GoogleAuthenticationProvider>((ref) {
14+
FirebaseAuthenticationState authenticationState = ref.watch(firebaseAuthenticationProvider);
15+
return GoogleAuthenticationProvider(
16+
loginHint: authenticationState is FirebaseAuthenticationStateLoggedIn ? authenticationState.user.email : null,
17+
);
18+
});
19+
20+
/// The Google authentication state provider.
21+
final googleAuthenticationStateProvider = NotifierProvider<FirebaseAuthenticationProviderNotifier, FirebaseAuthenticationState>(
22+
() => FirebaseAuthenticationProviderNotifier(googleAuthenticationProvider),
23+
);
1324

1425
/// The provider that allows to sign-in using Google.
1526
class GoogleAuthenticationProvider extends FirebaseAuthenticationProvider with LinkProvider, FallbackAuthenticationProvider<GoogleSignIn> {
27+
/// The login hint.
28+
final String? loginHint;
29+
1630
/// Creates a new Google authentication provider instance.
17-
GoogleAuthenticationProvider()
18-
: super(
31+
const GoogleAuthenticationProvider({
32+
this.loginHint,
33+
}) : super(
1934
availablePlatforms: const [
2035
Platform.android,
2136
Platform.iOS,
@@ -29,8 +44,8 @@ class GoogleAuthenticationProvider extends FirebaseAuthenticationProvider with L
2944
@override
3045
GoogleAuthMethod createDefaultAuthMethod(BuildContext context, {List<String> scopes = const []}) {
3146
Map<String, String> customParameters = {};
32-
if (state is FirebaseAuthenticationStateLoggedIn) {
33-
customParameters['login_hint'] = (state as FirebaseAuthenticationStateLoggedIn).user.email;
47+
if (loginHint != null) {
48+
customParameters['login_hint'] = loginHint!;
3449
}
3550
return GoogleAuthMethod.defaultMethod(
3651
scopes: scopes,
@@ -40,9 +55,9 @@ class GoogleAuthenticationProvider extends FirebaseAuthenticationProvider with L
4055

4156
@override
4257
GoogleAuthMethod createRestAuthMethod(BuildContext context, OAuth2Response response) => GoogleAuthMethod.rest(
43-
idToken: response.idToken,
44-
accessToken: response.accessToken,
45-
);
58+
idToken: response.idToken,
59+
accessToken: response.accessToken,
60+
);
4661

4762
@override
4863
GoogleSignIn createFallbackAuthProvider() => GoogleSignIn(
Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_riverpod/flutter_riverpod.dart';
33
import 'package:open_authenticator/app.dart';
4+
import 'package:open_authenticator/model/authentication/firebase_authentication.dart';
45
import 'package:open_authenticator/model/authentication/providers/provider.dart';
56
import 'package:open_authenticator/model/authentication/state.dart';
67
import 'package:open_authenticator/utils/firebase_auth/firebase_auth.dart';
@@ -9,13 +10,27 @@ import 'package:open_authenticator/utils/validation/sign_in/microsoft.dart';
910
import 'package:open_authenticator/utils/validation/sign_in/oauth2.dart';
1011

1112
/// The Microsoft authentication provider.
12-
final microsoftAuthenticationProvider = NotifierProvider<MicrosoftAuthenticationProvider, FirebaseAuthenticationState>(MicrosoftAuthenticationProvider.new);
13+
final microsoftAuthenticationProvider = Provider<MicrosoftAuthenticationProvider>((ref) {
14+
FirebaseAuthenticationState authenticationState = ref.watch(firebaseAuthenticationProvider);
15+
return MicrosoftAuthenticationProvider(
16+
loginHint: authenticationState is FirebaseAuthenticationStateLoggedIn ? authenticationState.user.email : null,
17+
);
18+
});
19+
20+
/// The Microsoft authentication state provider.
21+
final microsoftAuthenticationStateProvider = NotifierProvider<FirebaseAuthenticationProviderNotifier, FirebaseAuthenticationState>(
22+
() => FirebaseAuthenticationProviderNotifier(microsoftAuthenticationProvider),
23+
);
1324

1425
/// The provider that allows to sign-in using Microsoft.
1526
class MicrosoftAuthenticationProvider extends FirebaseAuthenticationProvider with LinkProvider, FallbackAuthenticationProvider<MicrosoftSignIn> {
27+
/// The login hint.
28+
final String? loginHint;
29+
1630
/// Creates a new Microsoft authentication provider instance.
17-
MicrosoftAuthenticationProvider()
18-
: super(
31+
const MicrosoftAuthenticationProvider({
32+
this.loginHint,
33+
}) : super(
1934
availablePlatforms: const [
2035
Platform.android,
2136
Platform.iOS,
@@ -29,8 +44,8 @@ class MicrosoftAuthenticationProvider extends FirebaseAuthenticationProvider wit
2944
@override
3045
MicrosoftAuthMethod createDefaultAuthMethod(BuildContext context, {List<String> scopes = const []}) {
3146
Map<String, String> customParameters = {};
32-
if (state is FirebaseAuthenticationStateLoggedIn) {
33-
customParameters['login_hint'] = (state as FirebaseAuthenticationStateLoggedIn).user.email;
47+
if (loginHint != null) {
48+
customParameters['login_hint'] = loginHint!;
3449
}
3550
return MicrosoftAuthMethod.defaultMethod(
3651
scopes: scopes,
@@ -40,14 +55,14 @@ class MicrosoftAuthenticationProvider extends FirebaseAuthenticationProvider wit
4055

4156
@override
4257
MicrosoftAuthMethod createRestAuthMethod(BuildContext context, OAuth2Response response) => MicrosoftAuthMethod.rest(
43-
accessToken: response.accessToken,
44-
idToken: response.idToken,
45-
nonce: response.nonce,
46-
);
58+
accessToken: response.accessToken,
59+
idToken: response.idToken,
60+
nonce: response.nonce,
61+
);
4762

4863
@override
4964
MicrosoftSignIn createFallbackAuthProvider() => MicrosoftSignIn(
50-
clientId: AppCredentials.azureSignInClientId,
51-
timeout: fallbackTimeout,
52-
);
65+
clientId: AppCredentials.azureSignInClientId,
66+
timeout: fallbackTimeout,
67+
);
5368
}

0 commit comments

Comments
 (0)