2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-05-29 15:10:11 +00:00
|
|
|
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
|
|
|
|
2020-09-22 18:32:43 +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
|
|
|
|
2020-05-29 15:10:11 +00:00
|
|
|
Color get backgroundLightColor => Colors.white;
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2020-08-19 17:57:06 +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
|
|
|
|
2020-09-22 18:32:43 +00:00
|
|
|
bool get extendBodyBehindAppBar => false;
|
|
|
|
|
2020-07-31 15:29:21 +00:00
|
|
|
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-28 15:47:43 +00:00
|
|
|
bool get _isDarkTheme => getIt.get<SettingsStore>().isDarkTheme;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-07-31 15:29:21 +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;
|
|
|
|
}
|
|
|
|
|
2020-08-19 17:57:06 +00:00
|
|
|
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 =
|
|
|
|
_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(
|
2020-04-30 18:59:57 +00:00
|
|
|
fontSize: 18.0,
|
2020-04-24 17:34:32 +00:00
|
|
|
fontWeight: FontWeight.bold,
|
2020-09-22 19:26:20 +00:00
|
|
|
fontFamily: 'Poppins',
|
2020-08-19 17:57:06 +00:00
|
|
|
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 =
|
|
|
|
_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),
|
2020-09-22 18:32:43 +00:00
|
|
|
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),
|
2020-09-22 18:32:43 +00:00
|
|
|
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),
|
2020-09-22 18:32:43 +00:00
|
|
|
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(
|
2020-07-31 15:29:21 +00:00
|
|
|
key: _scaffoldKey,
|
2020-06-20 07:10:00 +00:00
|
|
|
backgroundColor:
|
|
|
|
_isDarkTheme ? backgroundDarkColor : backgroundLightColor,
|
2020-01-04 19:31:52 +00:00
|
|
|
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
|
2020-09-22 18:32:43 +00:00
|
|
|
extendBodyBehindAppBar: extendBodyBehindAppBar,
|
2020-07-31 15:29:21 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|