Surface/lib/widgets/navigation/app_scaffold.dart

64 lines
2.1 KiB
Dart
Raw Normal View History

2024-11-09 10:28:45 +00:00
import 'package:easy_localization/easy_localization.dart';
2024-11-08 16:09:46 +00:00
import 'package:flutter/material.dart';
2024-11-09 10:28:45 +00:00
import 'package:go_router/go_router.dart';
2024-11-08 16:09:46 +00:00
import 'package:responsive_framework/responsive_framework.dart';
2024-11-09 10:28:45 +00:00
import 'package:surface/widgets/dialog.dart';
2024-11-08 16:09:46 +00:00
import 'package:surface/widgets/navigation/app_background.dart';
import 'package:surface/widgets/navigation/app_bottom_navigation.dart';
2024-11-13 16:08:09 +00:00
import 'package:surface/widgets/navigation/app_drawer_navigation.dart';
2024-11-08 16:09:46 +00:00
class AppScaffold extends StatelessWidget {
final PreferredSizeWidget? appBar;
2024-11-09 17:34:58 +00:00
final FloatingActionButtonLocation? floatingActionButtonLocation;
final Widget? floatingActionButton;
2024-11-09 10:28:45 +00:00
final String? title;
2024-11-08 16:09:46 +00:00
final Widget? body;
2024-11-09 10:28:45 +00:00
final bool autoImplyAppBar;
final bool showBottomNavigation;
2024-11-13 16:08:09 +00:00
final bool showDrawer;
2024-11-09 10:28:45 +00:00
const AppScaffold({
super.key,
this.appBar,
2024-11-09 17:34:58 +00:00
this.floatingActionButton,
this.floatingActionButtonLocation,
2024-11-09 10:28:45 +00:00
this.title,
this.body,
this.autoImplyAppBar = false,
this.showBottomNavigation = false,
2024-11-13 16:08:09 +00:00
this.showDrawer = false,
2024-11-09 10:28:45 +00:00
});
2024-11-08 16:09:46 +00:00
@override
Widget build(BuildContext context) {
2024-11-13 16:08:09 +00:00
final isShowDrawer = showDrawer;
2024-11-09 10:28:45 +00:00
final isShowBottomNavigation = (showBottomNavigation)
2024-11-13 16:08:09 +00:00
? (ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE))
2024-11-08 16:09:46 +00:00
: false;
2024-11-09 10:28:45 +00:00
final state = GoRouter.maybeOf(context);
2024-11-08 16:09:46 +00:00
return AppBackground(
child: Scaffold(
2024-11-09 10:28:45 +00: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-08 16:09:46 +00:00
body: body,
2024-11-09 17:34:58 +00:00
floatingActionButtonLocation: floatingActionButtonLocation,
floatingActionButton: floatingActionButton,
2024-11-13 16:08:09 +00:00
drawer: isShowDrawer ? AppNavigationDrawer() : null,
2024-11-08 16:09:46 +00:00
bottomNavigationBar:
isShowBottomNavigation ? AppBottomNavigationBar() : null,
),
);
}
}