cake_wallet/lib/src/screens/base_page.dart

147 lines
4.4 KiB
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/palette.dart';
2020-09-28 15:47:43 +00:00
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/src/widgets/nav_bar.dart';
2020-01-04 19:31:52 +00:00
enum AppBarStyle { regular, withShadow, transparent }
2020-01-04 19:31:52 +00:00
abstract class BasePage extends StatelessWidget {
2020-09-28 15:47:43 +00:00
BasePage()
: _scaffoldKey = GlobalKey<ScaffoldState>(),
_closeButtonImage = Image.asset('assets/images/close_button.png'),
_closeButtonImageDarkTheme =
Image.asset('assets/images/close_button_dark_theme.png');
final GlobalKey<ScaffoldState> _scaffoldKey;
final Image _closeButtonImage;
final Image _closeButtonImageDarkTheme;
2020-01-04 19:31:52 +00:00
String get title => null;
2020-06-20 07:10:00 +00:00
2020-01-04 19:31:52 +00:00
bool get isModalBackButton => false;
2020-06-20 07:10:00 +00:00
Color get backgroundLightColor => Colors.white;
2020-06-20 07:10:00 +00:00
Color get backgroundDarkColor => PaletteDark.backgroundColor;
Color get titleColor => null;
2020-06-20 07:10:00 +00:00
2020-01-04 19:31:52 +00:00
bool get resizeToAvoidBottomPadding => true;
2020-06-20 07:10:00 +00:00
bool get extendBodyBehindAppBar => false;
Widget get endDrawer => null;
2020-01-04 19:31:52 +00:00
AppBarStyle get appBarStyle => AppBarStyle.regular;
2020-06-20 07:10:00 +00:00
Widget Function(BuildContext, Widget) get rootWrapper => null;
2020-09-29 17:56:11 +00:00
bool get isDarkTheme => getIt.get<SettingsStore>().isDarkTheme;
2020-01-04 19:31:52 +00:00
void onOpenEndDrawer() => _scaffoldKey.currentState.openEndDrawer();
2020-01-04 19:31:52 +00:00
void onClose(BuildContext context) => Navigator.of(context).pop();
Widget leading(BuildContext context) {
if (ModalRoute.of(context).isFirst) {
return null;
}
final _backButton = Image.asset('assets/images/back_arrow.png',
2020-09-28 15:47:43 +00:00
color: titleColor ?? Theme.of(context).primaryTextTheme.title.color);
final _closeButton =
2020-09-29 17:56:11 +00:00
isDarkTheme ? _closeButtonImageDarkTheme : _closeButtonImage;
2020-01-04 19:31:52 +00:00
return SizedBox(
height: 37,
width: isModalBackButton ? 37 : 20,
child: ButtonTheme(
minWidth: double.minPositive,
child: FlatButton(
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
padding: EdgeInsets.all(0),
onPressed: () => onClose(context),
child: isModalBackButton ? _closeButton : _backButton),
),
);
}
Widget middle(BuildContext context) {
return title == null
? null
: Text(
title,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins',
color: titleColor ??
2020-09-28 15:47:43 +00:00
Theme.of(context).primaryTextTheme.title.color),
2020-01-04 19:31:52 +00:00
);
}
Widget trailing(BuildContext context) => null;
Widget floatingActionButton(BuildContext context) => null;
2020-01-08 12:26:34 +00:00
ObstructingPreferredSizeWidget appBar(BuildContext context) {
2020-09-28 15:47:43 +00:00
final appBarColor =
2020-09-29 17:56:11 +00:00
isDarkTheme ? backgroundDarkColor : backgroundLightColor;
2020-01-04 19:31:52 +00:00
switch (appBarStyle) {
case AppBarStyle.regular:
return NavBar(
context: context,
leading: leading(context),
middle: middle(context),
trailing: trailing(context),
backgroundColor: appBarColor);
2020-01-04 19:31:52 +00:00
case AppBarStyle.withShadow:
return NavBar.withShadow(
context: context,
leading: leading(context),
middle: middle(context),
trailing: trailing(context),
backgroundColor: appBarColor);
case AppBarStyle.transparent:
return CupertinoNavigationBar(
leading: leading(context),
middle: middle(context),
trailing: trailing(context),
backgroundColor: Colors.transparent,
border: null,
);
2020-01-04 19:31:52 +00:00
default:
return NavBar(
context: context,
leading: leading(context),
middle: middle(context),
trailing: trailing(context),
backgroundColor: appBarColor);
2020-01-04 19:31:52 +00:00
}
}
Widget body(BuildContext context);
@override
Widget build(BuildContext context) {
2020-06-20 07:10:00 +00:00
final root = Scaffold(
key: _scaffoldKey,
2020-06-20 07:10:00 +00:00
backgroundColor:
2020-09-29 17:56:11 +00:00
isDarkTheme ? backgroundDarkColor : backgroundLightColor,
2020-01-04 19:31:52 +00:00
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
extendBodyBehindAppBar: extendBodyBehindAppBar,
endDrawer: endDrawer,
2020-01-04 19:31:52 +00:00
appBar: appBar(context),
2020-09-28 15:47:43 +00:00
body: body(context),
2020-01-04 19:31:52 +00:00
floatingActionButton: floatingActionButton(context));
2020-06-20 07:10:00 +00:00
return rootWrapper?.call(context, root) ?? root;
2020-01-04 19:31:52 +00:00
}
}