Surface/lib/widgets/navigation/app_scaffold.dart

157 lines
5.6 KiB
Dart
Raw Normal View History

import 'dart:io';
import 'package:bitsdojo_window/bitsdojo_window.dart';
2024-11-09 10:28:45 +00:00
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/foundation.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';
import 'package:google_fonts/google_fonts.dart';
2024-11-08 16:09:46 +00:00
import 'package:responsive_framework/responsive_framework.dart';
import 'package:styled_widget/styled_widget.dart';
2024-11-15 15:08:29 +00:00
import 'package:surface/providers/navigation.dart';
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';
import 'package:surface/widgets/navigation/app_rail_navigation.dart';
2024-11-08 16:09:46 +00:00
final globalRootScaffoldKey = GlobalKey<ScaffoldState>();
2024-11-15 15:08:29 +00:00
class AppPageScaffold extends StatelessWidget {
2024-11-09 10:28:45 +00:00
final String? title;
2024-11-08 16:09:46 +00:00
final Widget? body;
final bool showAppBar;
2024-11-09 10:28:45 +00:00
final bool showBottomNavigation;
2024-12-08 11:59:04 +00:00
2024-11-15 15:08:29 +00:00
const AppPageScaffold({
2024-11-09 10:28:45 +00:00
super.key,
this.title,
this.body,
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 state = GoRouter.maybeOf(context);
2024-12-08 11:59:04 +00:00
final routeName = state?.routerDelegate.currentConfiguration.last.route.name;
2024-11-15 15:08:29 +00:00
2024-12-08 11:59:04 +00:00
final autoTitle = state != null ? 'screen${routeName?.capitalize()}' : 'screen';
2024-11-09 10:28:45 +00:00
return Scaffold(
appBar: showAppBar
? AppBar(
title: Text(title ?? autoTitle.tr()),
)
: null,
body: body,
2024-11-08 16:09:46 +00:00
);
}
}
2024-11-13 16:20:59 +00:00
class AppRootScaffold extends StatelessWidget {
final Widget body;
2024-12-08 11:59:04 +00:00
const AppRootScaffold({super.key, required this.body});
2024-11-14 05:02:42 +00:00
@override
Widget build(BuildContext context) {
final devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
2024-12-08 11:59:04 +00:00
final isCollapseDrawer = ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE);
final isExpandDrawer = ResponsiveBreakpoints.of(context).largerThan(TABLET);
2024-12-08 11:59:04 +00:00
final routeName = GoRouter.of(context).routerDelegate.currentConfiguration.last.route.name;
final isShowBottomNavigation = NavigationProvider.kShowBottomNavScreen.contains(routeName)
? ResponsiveBreakpoints.of(context).smallerOrEqualTo(MOBILE)
: false;
final isPopable = !NavigationProvider.kAllDestination.map((ele) => ele.screen).contains(routeName);
2024-11-15 15:08:29 +00:00
final innerWidget = isCollapseDrawer
? body
: Row(
children: [
Container(
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Theme.of(context).dividerColor,
width: 1 / devicePixelRatio,
),
),
),
2024-12-08 11:59:04 +00:00
child: isExpandDrawer ? AppNavigationDrawer(elevation: 0) : AppRailNavigation(),
),
Expanded(child: body),
],
);
2024-11-13 16:20:59 +00:00
final windowButtonColor = WindowButtonColors(
iconNormal: Theme.of(context).colorScheme.primary,
mouseOver: Theme.of(context).colorScheme.primaryContainer,
mouseDown: Theme.of(context).colorScheme.onPrimaryContainer,
iconMouseOver: Theme.of(context).colorScheme.primary,
iconMouseDown: Theme.of(context).colorScheme.primary,
);
return AppBackground(
2024-11-21 14:55:00 +00:00
isRoot: true,
child: Scaffold(
key: globalRootScaffoldKey,
body: Column(
children: [
2024-12-08 11:59:04 +00:00
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS))
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Theme.of(context).dividerColor,
width: 1 / devicePixelRatio,
),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
2024-12-08 11:59:04 +00:00
mainAxisAlignment: Platform.isMacOS ? MainAxisAlignment.center : MainAxisAlignment.start,
children: [
WindowTitleBarBox(
child: MoveWindow(
child: Text(
'Solian',
style: GoogleFonts.spaceGrotesk(),
).padding(horizontal: 12, vertical: 5),
),
),
2024-12-08 11:59:04 +00:00
if (!Platform.isMacOS)
Expanded(
child: WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
Row(
children: [
MinimizeWindowButton(colors: windowButtonColor),
MaximizeWindowButton(colors: windowButtonColor),
CloseWindowButton(colors: windowButtonColor),
],
),
],
),
),
),
],
),
),
ConnectionIndicator(),
Expanded(child: innerWidget),
],
),
drawer: !isExpandDrawer ? AppNavigationDrawer() : null,
drawerEdgeDragWidth: isPopable ? 0 : null,
2024-12-08 11:59:04 +00:00
bottomNavigationBar: isShowBottomNavigation ? AppBottomNavigationBar() : null,
),
);
2024-11-08 16:09:46 +00:00
}
}