2024-05-18 10:17:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2024-05-18 16:56:32 +00:00
|
|
|
import 'package:solian/router.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
import 'package:solian/theme.dart';
|
2024-05-22 15:18:01 +00:00
|
|
|
import 'package:solian/widgets/prev_page.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
import 'package:solian/widgets/navigation/app_navigation_bottom_bar.dart';
|
|
|
|
import 'package:solian/widgets/navigation/app_navigation_rail.dart';
|
2024-06-02 14:45:54 +00:00
|
|
|
import 'package:solian/widgets/sidebar/sidebar_placeholder.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
class NavShell extends StatelessWidget {
|
2024-05-23 14:11:42 +00:00
|
|
|
final bool showAppBar;
|
2024-06-27 06:31:15 +00:00
|
|
|
final bool showSidebar;
|
2024-05-18 10:17:16 +00:00
|
|
|
final GoRouterState state;
|
|
|
|
final Widget child;
|
|
|
|
|
2024-06-27 06:31:15 +00:00
|
|
|
final bool sidebarFirst;
|
|
|
|
final Widget? sidebar;
|
|
|
|
|
2024-05-23 14:11:42 +00:00
|
|
|
const NavShell({
|
|
|
|
super.key,
|
|
|
|
required this.child,
|
|
|
|
required this.state,
|
|
|
|
this.showAppBar = true,
|
2024-06-27 06:31:15 +00:00
|
|
|
this.showSidebar = true,
|
|
|
|
this.sidebarFirst = false,
|
|
|
|
this.sidebar,
|
2024-05-23 14:11:42 +00:00
|
|
|
});
|
2024-05-18 10:17:16 +00:00
|
|
|
|
2024-06-27 06:31:15 +00:00
|
|
|
List<Widget> buildContent(BuildContext context) {
|
|
|
|
return [
|
|
|
|
Flexible(
|
|
|
|
flex: 2,
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
if (SolianTheme.isExtraLargeScreen(context))
|
|
|
|
const VerticalDivider(thickness: 0.3, width: 1),
|
|
|
|
if (SolianTheme.isExtraLargeScreen(context))
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: sidebar ?? const SidebarPlaceholder(),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-05-18 10:17:16 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-18 16:56:32 +00:00
|
|
|
final canPop = AppRouter.instance.canPop();
|
|
|
|
|
2024-05-18 10:17:16 +00:00
|
|
|
return Scaffold(
|
2024-05-23 14:11:42 +00:00
|
|
|
appBar: showAppBar
|
|
|
|
? AppBar(
|
|
|
|
title: Text(state.topRoute?.name?.tr ?? 'page'.tr),
|
|
|
|
centerTitle: false,
|
|
|
|
titleSpacing: canPop ? null : 24,
|
|
|
|
elevation: SolianTheme.isLargeScreen(context) ? 1 : 0,
|
|
|
|
leading: canPop ? const PrevPageButton() : null,
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
)
|
|
|
|
: null,
|
2024-05-22 15:18:01 +00:00
|
|
|
bottomNavigationBar: SolianTheme.isLargeScreen(context)
|
|
|
|
? null
|
|
|
|
: const AppNavigationBottomBar(),
|
2024-05-18 10:17:16 +00:00
|
|
|
body: SolianTheme.isLargeScreen(context)
|
|
|
|
? Row(
|
|
|
|
children: [
|
|
|
|
const AppNavigationRail(),
|
|
|
|
const VerticalDivider(thickness: 0.3, width: 1),
|
2024-06-27 06:31:15 +00:00
|
|
|
if (showSidebar && sidebarFirst)
|
|
|
|
...buildContent(context).reversed
|
|
|
|
else if (showSidebar)
|
|
|
|
...buildContent(context)
|
|
|
|
else
|
|
|
|
Expanded(child: child),
|
2024-05-18 10:17:16 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
: child,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|