167 lines
5.7 KiB
Dart
167 lines
5.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
|
|
|
class CustomScaffold extends StatelessWidget {
|
|
final VoidCallback? onBackButton;
|
|
final VoidCallback? onScreenTap;
|
|
final String? titleText;
|
|
final bool avoidBottomInsets;
|
|
final bool? showShadow;
|
|
final bool showAppBar;
|
|
final bool enableLayoutBuilder;
|
|
final GlobalKey<ScaffoldState> screenKey;
|
|
final PreferredSizeWidget? appBar;
|
|
final Widget? body;
|
|
final Widget? sideDrawer;
|
|
final Widget? customTabViewWidget;
|
|
final Widget? bottomMenu;
|
|
final Widget? floatingActionButton;
|
|
final Color? backgroundColor;
|
|
|
|
const CustomScaffold({
|
|
Key? key,
|
|
this.onBackButton,
|
|
this.customTabViewWidget,
|
|
this.titleText,
|
|
this.appBar,
|
|
this.body,
|
|
this.showShadow,
|
|
this.bottomMenu,
|
|
this.floatingActionButton,
|
|
this.onScreenTap,
|
|
this.avoidBottomInsets = true,
|
|
this.showAppBar = false,
|
|
this.enableLayoutBuilder = true,
|
|
required this.screenKey,
|
|
this.backgroundColor,
|
|
this.sideDrawer,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final ModalRoute<dynamic>? parentRoute = ModalRoute.of(context);
|
|
final bool canPop = parentRoute?.canPop ?? false;
|
|
return GestureDetector(
|
|
onHorizontalDragEnd: GetPlatform.isIOS
|
|
? (details) {
|
|
if (details.velocity.pixelsPerSecond.dx > 0) {
|
|
if (onBackButton != null) {
|
|
onBackButton!();
|
|
} else {
|
|
if (canPop) {
|
|
Navigator.pop(context);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
: null,
|
|
onTap: () {
|
|
if (onScreenTap != null) onScreenTap!();
|
|
},
|
|
child: WillPopScope(
|
|
onWillPop: () async {
|
|
if (onBackButton != null) {
|
|
onBackButton!();
|
|
} else {
|
|
if (canPop) {
|
|
Navigator.pop(context);
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
child: LayoutBuilder(
|
|
builder: (context, constraint) {
|
|
if (constraint.maxWidth > 600 && enableLayoutBuilder) {
|
|
return Scaffold(
|
|
drawer: sideDrawer,
|
|
key: screenKey,
|
|
resizeToAvoidBottomInset: avoidBottomInsets,
|
|
drawerEnableOpenDragGesture: false,
|
|
endDrawerEnableOpenDragGesture: false,
|
|
backgroundColor: backgroundColor ?? CustomAppColors.kPrimaryColor,
|
|
body: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
const Spacer(),
|
|
Expanded(
|
|
flex: 2,
|
|
child: customTabViewWidget ??
|
|
Column(
|
|
mainAxisSize: MainAxisSize.max,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(
|
|
2.0.sp,
|
|
),
|
|
color: backgroundColor ??
|
|
CustomAppColors.kPrimaryColor,
|
|
),
|
|
padding: EdgeInsets.all(
|
|
10.0.sp,
|
|
),
|
|
child: body,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Spacer(),
|
|
],
|
|
),
|
|
appBar: showAppBar
|
|
? appBar ??
|
|
CustomAppBar(
|
|
titleText: titleText ?? "titleText",
|
|
onBackButtonPressed: () {
|
|
if (onBackButton != null) {
|
|
onBackButton!();
|
|
return;
|
|
}
|
|
if (canPop) {
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
)
|
|
: null,
|
|
floatingActionButton: floatingActionButton,
|
|
);
|
|
}
|
|
return Scaffold(
|
|
drawer: sideDrawer,
|
|
resizeToAvoidBottomInset: avoidBottomInsets,
|
|
key: screenKey,
|
|
floatingActionButton: floatingActionButton,
|
|
appBar: showAppBar
|
|
? appBar ??
|
|
CustomAppBar(
|
|
showBoxShadow: showShadow ?? false,
|
|
titleText: titleText ?? "titleText",
|
|
onBackButtonPressed: () {
|
|
if (onBackButton != null) {
|
|
onBackButton!();
|
|
return;
|
|
}
|
|
if (canPop) {
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
)
|
|
: null,
|
|
body: body ?? Container(),
|
|
backgroundColor:
|
|
backgroundColor ?? CustomAppColors.kPrimaryColor,
|
|
bottomNavigationBar: bottomMenu,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|