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-14 16:52:31 +00:00
|
|
|
import 'package:surface/widgets/connection_indicator.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-14 14:21:13 +00:00
|
|
|
import 'package:surface/widgets/navigation/app_rail_navigation.dart';
|
2024-11-08 16:09:46 +00:00
|
|
|
|
|
|
|
class AppScaffold extends StatelessWidget {
|
2024-11-09 10:28:45 +00:00
|
|
|
final String? title;
|
2024-11-08 16:09:46 +00:00
|
|
|
final Widget? body;
|
2024-11-14 14:21:13 +00:00
|
|
|
final bool showAppBar;
|
2024-11-09 10:28:45 +00:00
|
|
|
final bool showBottomNavigation;
|
|
|
|
const AppScaffold({
|
|
|
|
super.key,
|
|
|
|
this.title,
|
|
|
|
this.body,
|
2024-11-14 14:21:13 +00:00
|
|
|
this.showAppBar = true,
|
2024-11-09 10:28:45 +00:00
|
|
|
this.showBottomNavigation = false,
|
|
|
|
});
|
2024-11-08 16:09:46 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-09 10:28:45 +00:00
|
|
|
final isShowBottomNavigation = (showBottomNavigation)
|
2024-11-13 16:20:59 +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-14 14:21:13 +00:00
|
|
|
final autoTitle = state != null
|
|
|
|
? 'screen${state.routerDelegate.currentConfiguration.last.route.name?.capitalize()}'
|
|
|
|
: 'screen';
|
2024-11-09 10:28:45 +00:00
|
|
|
|
2024-11-14 14:21:13 +00:00
|
|
|
return Scaffold(
|
|
|
|
appBar: showAppBar
|
|
|
|
? AppBar(
|
|
|
|
title: Text(title ?? autoTitle.tr()),
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
body: body,
|
|
|
|
bottomNavigationBar:
|
|
|
|
isShowBottomNavigation ? AppBottomNavigationBar() : null,
|
2024-11-08 16:09:46 +00:00
|
|
|
);
|
2024-11-14 14:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
2024-11-13 16:20:59 +00:00
|
|
|
|
2024-11-14 14:21:13 +00:00
|
|
|
class AppRootScaffold extends StatelessWidget {
|
|
|
|
final Widget body;
|
|
|
|
const AppRootScaffold({super.key, required this.body});
|
2024-11-14 05:02:42 +00:00
|
|
|
|
2024-11-14 14:21:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
|
|
|
|
|
|
|
|
final isCollapseDrawer =
|
|
|
|
ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE);
|
|
|
|
final isExpandDrawer = ResponsiveBreakpoints.of(context).largerThan(TABLET);
|
|
|
|
|
|
|
|
final innerWidget = isCollapseDrawer
|
|
|
|
? body
|
|
|
|
: Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
right: BorderSide(
|
|
|
|
color: Theme.of(context).dividerColor,
|
|
|
|
width: 1 / devicePixelRatio,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: isExpandDrawer
|
|
|
|
? AppNavigationDrawer(elevation: 0)
|
|
|
|
: AppRailNavigation(),
|
|
|
|
),
|
|
|
|
Expanded(child: body),
|
|
|
|
],
|
|
|
|
);
|
2024-11-13 16:20:59 +00:00
|
|
|
|
2024-11-14 14:21:13 +00:00
|
|
|
return AppBackground(
|
|
|
|
child: Scaffold(
|
2024-11-14 16:52:31 +00:00
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
ConnectionIndicator(),
|
|
|
|
Expanded(child: innerWidget),
|
|
|
|
],
|
|
|
|
),
|
2024-11-14 14:21:13 +00:00
|
|
|
drawer: !isExpandDrawer ? AppNavigationDrawer() : null,
|
|
|
|
),
|
|
|
|
);
|
2024-11-08 16:09:46 +00:00
|
|
|
}
|
|
|
|
}
|