Solian/lib/shells/sidebar_shell.dart

63 lines
1.7 KiB
Dart
Raw Normal View History

2024-05-22 15:18:01 +00:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:go_router/go_router.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/app_bar_leading.dart';
2024-06-22 15:59:11 +00:00
import 'package:solian/widgets/app_bar_title.dart';
2024-06-27 06:31:15 +00:00
import 'package:solian/widgets/sidebar/sidebar_placeholder.dart';
2024-05-22 15:18:01 +00:00
2024-07-12 13:59:16 +00:00
class SidebarShell extends StatelessWidget {
2024-06-27 06:31:15 +00:00
final bool showAppBar;
2024-05-22 15:18:01 +00:00
final GoRouterState state;
final Widget child;
2024-06-27 06:31:15 +00:00
final bool sidebarFirst;
final Widget? sidebar;
2024-07-12 13:59:16 +00:00
const SidebarShell({
2024-06-27 06:31:15 +00:00
super.key,
required this.child,
required this.state,
this.showAppBar = true,
this.sidebarFirst = false,
this.sidebar,
});
List<Widget> buildContent(BuildContext context) {
return [
Flexible(
flex: 2,
child: child,
),
if (AppTheme.isExtraLargeScreen(context))
2024-06-27 06:31:15 +00:00
const VerticalDivider(thickness: 0.3, width: 1),
if (AppTheme.isExtraLargeScreen(context))
2024-06-27 06:31:15 +00:00
Flexible(
flex: 1,
child: sidebar ?? const SidebarPlaceholder(),
),
];
}
2024-05-22 15:18:01 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
2024-06-27 06:31:15 +00:00
appBar: showAppBar
? AppBar(
2024-07-12 14:37:58 +00:00
leading: AppBarLeadingButton.adaptive(context),
2024-06-27 06:31:15 +00:00
title: AppBarTitle(state.topRoute?.name?.tr ?? 'page'.tr),
centerTitle: false,
toolbarHeight: AppTheme.toolbarHeight(context),
2024-06-27 06:31:15 +00:00
)
: null,
body: AppTheme.isLargeScreen(context)
2024-06-27 06:31:15 +00:00
? Row(
children: sidebarFirst
? buildContent(context).reversed.toList()
: buildContent(context),
)
: child,
2024-05-22 15:18:01 +00:00
);
}
}