Created
April 27, 2025 18:10
-
-
Save fredgrott/dc82b5be7cac56edd1e24bf2a2d61941 to your computer and use it in GitHub Desktop.
current route state notifier (the vm)
This file contains hidden or 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
import 'package:app_scaffold/flex/flex_target.dart'; | |
import 'package:state_notifier/state_notifier.dart'; | |
import 'package:userinterface/core/navigation/models/current_route.dart'; | |
/// StateNotifier for the immutable AppNavigation data. | |
/// For Service Locator injection, this class is registered | |
/// With GetIt. In Provider type ionjectors, we make | |
/// A separate NotifierProvider class. | |
/// | |
/// Many people mistakenly label this as a controller, its | |
/// not that but a model-view. | |
class CurrentRouteStateNotifier extends StateNotifier<CurrentRoute> { | |
CurrentRouteStateNotifier([CurrentRoute? appNavigation]) | |
: super(appNavigation ?? const CurrentRoute(pushedDestination: FlexTarget(), destination: FlexTarget())); | |
void setDestination(FlexTarget value) { | |
state = state.copyWith(destination: value, usePush: false); | |
} | |
void setModalDestination(FlexTarget value) { | |
state = state.copyWith(pushedDestination: value, usePush: true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment