mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 12:42:34 +00:00
73 lines
2.0 KiB
Dart
73 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:lunasea/database/tables/lunasea.dart';
|
|
import 'package:lunasea/modules.dart';
|
|
import 'package:lunasea/system/platform.dart';
|
|
|
|
class LunaScaffold extends StatelessWidget {
|
|
final GlobalKey<ScaffoldState> scaffoldKey;
|
|
final LunaModule? module;
|
|
final PreferredSizeWidget? appBar;
|
|
final Widget? body;
|
|
final Widget? drawer;
|
|
final Widget? bottomNavigationBar;
|
|
final Widget? floatingActionButton;
|
|
final bool extendBody;
|
|
final bool extendBodyBehindAppBar;
|
|
|
|
/// Called when [LunaSeaDatabase.ENABLED_PROFILE] has changed. Triggered within the build function.
|
|
final void Function(BuildContext)? onProfileChange;
|
|
|
|
// ignore: use_key_in_widget_constructors
|
|
const LunaScaffold({
|
|
required this.scaffoldKey,
|
|
this.module,
|
|
this.appBar,
|
|
this.body,
|
|
this.drawer,
|
|
this.bottomNavigationBar,
|
|
this.floatingActionButton,
|
|
this.extendBody = false,
|
|
this.extendBodyBehindAppBar = false,
|
|
this.onProfileChange,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (LunaPlatform.isAndroid) {
|
|
return WillPopScope(
|
|
onWillPop: () async {
|
|
final state = scaffoldKey.currentState;
|
|
if (state?.hasDrawer ?? false) {
|
|
if (state!.isDrawerOpen) return true;
|
|
state.openDrawer();
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
child: scaffold,
|
|
);
|
|
}
|
|
|
|
return scaffold;
|
|
}
|
|
|
|
Widget get scaffold {
|
|
return LunaSeaDatabase.ENABLED_PROFILE.watch(
|
|
builder: (context, _) {
|
|
onProfileChange?.call(context);
|
|
return Scaffold(
|
|
key: scaffoldKey,
|
|
appBar: appBar,
|
|
body: body,
|
|
drawer: drawer,
|
|
bottomNavigationBar: bottomNavigationBar,
|
|
floatingActionButton: floatingActionButton,
|
|
extendBody: extendBody,
|
|
extendBodyBehindAppBar: extendBodyBehindAppBar,
|
|
onDrawerChanged: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|