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 { extension ProtectedPageBuildContextExtension on NavigatorState {
Future<T?> pushReplacementProtected<T extends Object?, U extends Object?>( Future<T?>
pushReplacementNamedProtected<T extends Object?, U extends Object?>(
String routeName, { String routeName, {
U? result, U? result,
Object? arguments, Object? arguments,
@ -41,7 +42,7 @@ extension ProtectedPageBuildContextExtension on NavigatorState {
} }
} }
Future<T?> pushProtected<T extends Object?>( Future<T?> pushNamedProtected<T extends Object?>(
String routeName, { String routeName, {
Object? arguments, Object? arguments,
}) async { }) 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 { Future<bool> _auth() async {
final securePrefController = context.read<SecurePrefController>(); final securePrefController = context.read<SecurePrefController>();
switch (securePrefController.protectedPageAuthTypeValue) { switch (securePrefController.protectedPageAuthTypeValue) {

View file

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