Skip to content

Instantly share code, notes, and snippets.

@fredgrott
Created April 27, 2025 18:08
Show Gist options
  • Save fredgrott/35acf6efae7a6e22f669794dd9c1b818 to your computer and use it in GitHub Desktop.
Save fredgrott/35acf6efae7a6e22f669794dd9c1b818 to your computer and use it in GitHub Desktop.
navigation shell using HookWidget
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:userinterface/core/custom_hooks/use_create_state_notifier.dart';
import 'package:userinterface/core/custom_hooks/use_state_notifier.dart';
import 'package:userinterface/core/navigation/model_views/app_navigation_state.dart';
import 'package:userinterface/core/navigation/models/current_route.dart';
const bool _debug = kDebugMode && true;
/// For interacting with [Go Router] one writes
/// a navigation shell. Since Flex Scaffold makes
/// use of state via State Notifier we do not have
/// to use StatefulShellRoute which translates to
/// an easier time implementing screen transitions.
///
/// If we are using provider style DI than its a
/// Consumer like widget, if using service locator
/// DI its a HookWWidget as watch_it has noting to
/// hook up state notifiers.
class NavigationShell extends HookWidget {
const NavigationShell({super.key, required this.body});
final Widget body;
@override
Widget build(BuildContext context) {
// non-widget-di way using hooks
final notifier = useCreateStateNotifier(() => CurrentRouteStateNotifier());
final state = useStateNotifier(notifier);
final CurrentRoute route = state;
final String goRouterPath = GoRouterState.of(context).uri.toString();
if (_debug) debugPrint('LayoutShell: goRouterPath = $goRouterPath');
return Container();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment