Solian/lib/shells/root_shell.dart

86 lines
2.5 KiB
Dart
Raw Permalink Normal View History

import 'package:firebase_analytics/firebase_analytics.dart';
2024-07-06 12:55:53 +00:00
import 'package:flutter/material.dart';
2024-07-12 05:15:46 +00:00
import 'package:go_router/go_router.dart';
2024-07-06 12:55:53 +00:00
import 'package:solian/theme.dart';
2024-10-04 19:38:30 +00:00
import 'package:solian/widgets/navigation/app_navigation.dart';
import 'package:solian/widgets/navigation/app_navigation_bottom.dart';
import 'package:solian/widgets/navigation/app_navigation_rail.dart';
2024-07-06 12:55:53 +00:00
2024-07-12 03:39:44 +00:00
final GlobalKey<ScaffoldState> rootScaffoldKey = GlobalKey<ScaffoldState>();
2024-07-06 12:55:53 +00:00
class RootShell extends StatelessWidget {
final bool showSidebar;
final bool showNavigation;
final bool? showBottomNavigation;
2024-07-12 05:15:46 +00:00
final GoRouterState state;
2024-07-06 12:55:53 +00:00
final Widget child;
const RootShell({
super.key,
2024-07-12 05:15:46 +00:00
required this.state,
2024-07-06 12:55:53 +00:00
required this.child,
this.showSidebar = true,
this.showNavigation = true,
this.showBottomNavigation,
});
2024-07-12 03:39:44 +00:00
void closeDrawer() {
rootScaffoldKey.currentState!.closeDrawer();
}
2024-07-06 12:55:53 +00:00
@override
Widget build(BuildContext context) {
2024-07-12 05:15:46 +00:00
final routeName = state.topRoute?.name;
if (routeName != null) {
FirebaseAnalytics.instance.logEvent(
name: 'screen_view',
parameters: {
'firebase_screen': routeName,
},
);
}
final showRailNavigation = AppTheme.isLargeScreen(context);
2024-10-17 14:44:00 +00:00
final destNames = [
'postDetail',
...AppNavigation.destinations.map((x) => x.page),
];
final showBottomNavigation =
destNames.contains(routeName) && !showRailNavigation;
2024-10-04 19:38:30 +00:00
2024-07-06 12:55:53 +00:00
return Scaffold(
2024-07-12 03:39:44 +00:00
key: rootScaffoldKey,
2024-10-07 16:06:08 +00:00
backgroundColor: Theme.of(context).colorScheme.surface,
2024-10-04 19:38:30 +00:00
bottomNavigationBar: showBottomNavigation
? AppNavigationBottom(
2024-10-17 14:44:00 +00:00
initialIndex: AppNavigation.destinations
.map((x) => x.page)
.toList()
.indexOf(routeName ?? 'page'),
2024-10-04 19:38:30 +00:00
)
: null,
body: AppTheme.isLargeScreen(context)
? Row(
children: [
2024-10-17 14:44:00 +00:00
if (showRailNavigation)
AppNavigationRail(
initialIndex: AppNavigation.destinations
.map((x) => x.page)
.toList()
.indexOf(routeName ?? 'page'),
),
if (showRailNavigation)
const VerticalDivider(
width: 0.3,
thickness: 0.3,
),
Expanded(child: child),
],
)
2024-07-12 03:39:44 +00:00
: child,
2024-07-06 12:55:53 +00:00
);
}
}