NavigationLogic constructor

NavigationLogic({
  1. Widget defaultLoading()?,
  2. required BuildContext context,
  3. required Widget initialScreen(),
  4. required PathsBuilder rootPaths,
  5. Stream? authState,
  6. FeatureAccessController? featureAccessController,
})

Creates a new NavigationLogic instance.

Throws an exception if more than one instance is attempted to be created.

Implementation

NavigationLogic({
  this.defaultLoading,
  required this.context,
  required this.initialScreen,
  required this.rootPaths,
  this.authState,
  this.featureAccessController,
}) : _currentScreen = initialScreen() {
  _routePath = rootPaths.bareBuilder('', initialScreen)();
  routerDelegate = StandardRouterDelegate(context, this);
  routerInformationParser = StandardRouteInformationParser(rootPaths);
  final authState = this.authState;

  rootPaths.accessDeniedRoute ??= _defaultAccessDeniedRoute();

  if (!_navigationLogicInitialised) {
    GetIt.instance.registerSingleton(this);
    _navigationLogicInitialised = true;
  } else {
    throw Exception('Only one instance of NavigationLogic can be created');
  }

  defaultLoading ??= () => const DefaultLoading();

  if (authState != null) {
    _onAuthStateChangedSubscription = authState.listen(_onAuthStateChanged);
  } else {
    _isInitialising = false;
  }

  if (!DirtyStateMonitor.isInitialised) {
    DirtyStateMonitor.initialise();
  }
}