Skip to content

Instantly share code, notes, and snippets.

@fredgrott
Created April 27, 2025 18:10
Show Gist options
  • Save fredgrott/dc82b5be7cac56edd1e24bf2a2d61941 to your computer and use it in GitHub Desktop.
Save fredgrott/dc82b5be7cac56edd1e24bf2a2d61941 to your computer and use it in GitHub Desktop.
current route state notifier (the vm)
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