Solian/lib/shells/root_shell.dart

60 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-07-12 03:39:44 +00:00
import 'package:solian/widgets/navigation/app_navigation_drawer.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-07-06 12:55:53 +00:00
return Scaffold(
2024-07-12 03:39:44 +00:00
key: rootScaffoldKey,
drawer: AppTheme.isLargeScreen(context)
2024-07-12 08:19:54 +00:00
? null
: AppNavigationDrawer(routeName: routeName),
body: AppTheme.isLargeScreen(context)
? Row(
children: [
2024-07-12 08:19:54 +00:00
if (showNavigation) AppNavigationDrawer(routeName: routeName),
if (showNavigation)
const VerticalDivider(thickness: 0.3, width: 1),
Expanded(child: child),
],
)
2024-07-12 03:39:44 +00:00
: child,
2024-07-06 12:55:53 +00:00
);
}
}