-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
335 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:octopus/src/state/state.dart' show OctopusState; | ||
|
||
/// Guard for the router. | ||
/// | ||
/// {@template guard} | ||
/// This is good place for checking permissions, authentication, etc. | ||
/// | ||
/// Return the new state or null to cancel navigation. | ||
/// If the returned state is null or throw an error, | ||
/// the router will not change the state at all. | ||
/// | ||
/// You should return the same state if you don't want to change it and | ||
/// continue navigation. | ||
/// | ||
/// You should return the new state if you want to change it and | ||
/// continue navigation. | ||
/// | ||
/// You should return null if you want to cancel navigation. | ||
/// | ||
/// If something changed in app state, you should notify the guard | ||
/// and router rerun the all guards with current state. | ||
/// {@endtemplate} | ||
abstract interface class IOctopusGuard implements Listenable { | ||
/// Called when the [OctopusState] changes. | ||
/// | ||
/// [history] is the history of the [OctopusState] states. | ||
/// [state] is the expected new state. | ||
/// | ||
/// {@macro guard} | ||
FutureOr<OctopusState?> call(List<OctopusState> history, OctopusState state); | ||
} | ||
|
||
/// {@macro guard} | ||
class OctopusGuard with ChangeNotifier implements IOctopusGuard { | ||
/// {@macro guard} | ||
OctopusGuard(); | ||
|
||
@override | ||
FutureOr<OctopusState?> call( | ||
List<OctopusState> history, | ||
OctopusState state, | ||
) => | ||
state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.