Solian/lib/shells/root_shell.dart

63 lines
1.6 KiB
Dart
Raw 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';
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,
},
);
}
2024-10-04 19:38:30 +00:00
final destNames = AppNavigation.destinations.map((x) => x.page).toList();
final showBottomNavigation = destNames.contains(routeName);
2024-07-06 12:55:53 +00:00
return Scaffold(
2024-07-12 03:39:44 +00:00
key: rootScaffoldKey,
2024-10-04 19:38:30 +00:00
bottomNavigationBar: showBottomNavigation
? AppNavigationBottom(
initialIndex: destNames.indexOf(routeName ?? 'page'),
)
: null,
body: AppTheme.isLargeScreen(context)
? Row(
children: [
Expanded(child: child),
],
)
2024-07-12 03:39:44 +00:00
: child,
2024-07-06 12:55:53 +00:00
);
}
}