2024-08-18 17:35:38 +00:00
|
|
|
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';
|
2024-10-04 19:12:47 +00:00
|
|
|
import 'package:solian/widgets/navigation/app_navigation_bottom.dart';
|
2024-10-05 17:17:49 +00:00
|
|
|
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;
|
|
|
|
|
2024-08-18 17:35:38 +00:00
|
|
|
if (routeName != null) {
|
|
|
|
FirebaseAnalytics.instance.logEvent(
|
|
|
|
name: 'screen_view',
|
|
|
|
parameters: {
|
|
|
|
'firebase_screen': routeName,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-10-05 17:17:49 +00:00
|
|
|
final showRailNavigation = AppTheme.isLargeScreen(context);
|
|
|
|
|
2024-10-04 19:38:30 +00:00
|
|
|
final destNames = AppNavigation.destinations.map((x) => x.page).toList();
|
2024-10-05 17:17:49 +00:00
|
|
|
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-04 19:38:30 +00:00
|
|
|
bottomNavigationBar: showBottomNavigation
|
|
|
|
? AppNavigationBottom(
|
|
|
|
initialIndex: destNames.indexOf(routeName ?? 'page'),
|
|
|
|
)
|
|
|
|
: null,
|
2024-09-13 12:22:10 +00:00
|
|
|
body: AppTheme.isLargeScreen(context)
|
2024-07-07 06:41:23 +00:00
|
|
|
? Row(
|
|
|
|
children: [
|
2024-10-05 17:17:49 +00:00
|
|
|
if (showRailNavigation) const AppNavigationRail(),
|
|
|
|
if (showRailNavigation)
|
|
|
|
const VerticalDivider(
|
|
|
|
width: 0.3,
|
|
|
|
thickness: 0.3,
|
|
|
|
),
|
2024-07-07 06:41:23 +00:00
|
|
|
Expanded(child: child),
|
|
|
|
],
|
|
|
|
)
|
2024-07-12 03:39:44 +00:00
|
|
|
: child,
|
2024-07-06 12:55:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|