Surface/lib/widgets/navigation/app_scaffold.dart

78 lines
2.5 KiB
Dart
Raw Normal View History

2024-11-09 18:28:45 +08:00
import 'package:easy_localization/easy_localization.dart';
2024-11-09 00:09:46 +08:00
import 'package:flutter/material.dart';
2024-11-09 18:28:45 +08:00
import 'package:go_router/go_router.dart';
2024-11-09 00:09:46 +08:00
import 'package:responsive_framework/responsive_framework.dart';
2024-11-09 18:28:45 +08:00
import 'package:surface/widgets/dialog.dart';
2024-11-09 00:09:46 +08:00
import 'package:surface/widgets/navigation/app_background.dart';
import 'package:surface/widgets/navigation/app_bottom_navigation.dart';
2024-11-14 00:08:09 +08:00
import 'package:surface/widgets/navigation/app_drawer_navigation.dart';
2024-11-09 00:09:46 +08:00
class AppScaffold extends StatelessWidget {
final PreferredSizeWidget? appBar;
2024-11-10 01:34:58 +08:00
final FloatingActionButtonLocation? floatingActionButtonLocation;
final Widget? floatingActionButton;
2024-11-09 18:28:45 +08:00
final String? title;
2024-11-09 00:09:46 +08:00
final Widget? body;
2024-11-09 18:28:45 +08:00
final bool autoImplyAppBar;
final bool showBottomNavigation;
2024-11-14 00:08:09 +08:00
final bool showDrawer;
2024-11-09 18:28:45 +08:00
const AppScaffold({
super.key,
this.appBar,
2024-11-10 01:34:58 +08:00
this.floatingActionButton,
this.floatingActionButtonLocation,
2024-11-09 18:28:45 +08:00
this.title,
this.body,
this.autoImplyAppBar = false,
this.showBottomNavigation = false,
2024-11-14 00:08:09 +08:00
this.showDrawer = false,
2024-11-09 18:28:45 +08:00
});
2024-11-09 00:09:46 +08:00
@override
Widget build(BuildContext context) {
2024-11-14 00:20:59 +08:00
final isShowDrawer = showDrawer
? ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE)
: false;
2024-11-09 18:28:45 +08:00
final isShowBottomNavigation = (showBottomNavigation)
2024-11-14 00:20:59 +08:00
? ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE)
2024-11-09 00:09:46 +08:00
: false;
2024-11-09 18:28:45 +08:00
final state = GoRouter.maybeOf(context);
2024-11-14 00:20:59 +08:00
final innerWidget = AppBackground(
2024-11-09 00:09:46 +08:00
child: Scaffold(
2024-11-09 18:28:45 +08:00
appBar: appBar ??
(autoImplyAppBar
? AppBar(
title: title != null
? Text(title!)
: state != null
? Text(
('screen${state.routerDelegate.currentConfiguration.last.route.name?.capitalize()}')
.tr(),
)
: null)
: null),
2024-11-09 00:09:46 +08:00
body: body,
2024-11-10 01:34:58 +08:00
floatingActionButtonLocation: floatingActionButtonLocation,
floatingActionButton: floatingActionButton,
2024-11-14 00:08:09 +08:00
drawer: isShowDrawer ? AppNavigationDrawer() : null,
2024-11-09 00:09:46 +08:00
bottomNavigationBar:
isShowBottomNavigation ? AppBottomNavigationBar() : null,
),
);
2024-11-14 00:20:59 +08:00
if (showDrawer) {
return Row(
children: [
AppNavigationDrawer(),
VerticalDivider(width: 1, color: Theme.of(context).dividerColor),
Expanded(child: innerWidget),
],
);
}
return innerWidget;
2024-11-09 00:09:46 +08:00
}
}