Update naming of the protected push methods in context

This commit is contained in:
Ming Ming 2024-05-26 18:45:54 +08:00
parent dbfca98d6d
commit 340cce297e
2 changed files with 12 additions and 3 deletions

View file

@ -28,7 +28,8 @@ class ProtectedPageAuthException implements Exception {
}
extension ProtectedPageBuildContextExtension on NavigatorState {
Future<T?> pushReplacementProtected<T extends Object?, U extends Object?>(
Future<T?>
pushReplacementNamedProtected<T extends Object?, U extends Object?>(
String routeName, {
U? result,
Object? arguments,
@ -41,7 +42,7 @@ extension ProtectedPageBuildContextExtension on NavigatorState {
}
}
Future<T?> pushProtected<T extends Object?>(
Future<T?> pushNamedProtected<T extends Object?>(
String routeName, {
Object? arguments,
}) async {
@ -52,6 +53,14 @@ extension ProtectedPageBuildContextExtension on NavigatorState {
}
}
Future<T?> pushProtected<T extends Object?>(Route<T> route) async {
if (await _auth()) {
return push(route);
} else {
throw const ProtectedPageAuthException();
}
}
Future<bool> _auth() async {
final securePrefController = context.read<SecurePrefController>();
switch (securePrefController.protectedPageAuthTypeValue) {

View file

@ -145,7 +145,7 @@ class _SplashState extends State<Splash> {
Navigator.pushReplacementNamed(context, SignIn.routeName);
} else {
Navigator.of(context)
.pushReplacementProtected(Home.routeName,
.pushReplacementNamedProtected(Home.routeName,
arguments: HomeArguments(account))
.then((value) async {
if (getRawPlatform() == NpPlatform.android) {