2020-12-15 19:43:50 +00:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
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()
|
2020-12-10 17:53:40 +00:00
|
|
|
: _scaffoldKey = GlobalKey<ScaffoldState>();
|
2020-09-28 15:47:43 +00:00
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey;
|
2020-12-10 17:53:40 +00:00
|
|
|
|
2020-12-14 17:54:56 +00:00
|
|
|
final Image closeButtonImage =
|
2020-12-10 17:53:40 +00:00
|
|
|
Image.asset('assets/images/close_button.png');
|
2020-12-14 17:54:56 +00:00
|
|
|
final Image closeButtonImageDarkTheme =
|
2020-12-10 17:53:40 +00:00
|
|
|
Image.asset('assets/images/close_button_dark_theme.png');
|
|
|
|
|
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-12-15 19:30:16 +00:00
|
|
|
ThemeBase get currentTheme => getIt.get<SettingsStore>().currentTheme;
|
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-11-09 15:01:58 +00:00
|
|
|
final _backButton = Icon(Icons.arrow_back_ios,
|
|
|
|
color: titleColor ?? Theme.of(context).primaryTextTheme.title.color,
|
2020-11-11 18:52:46 +00:00
|
|
|
size: 16,);
|
2020-12-15 19:30:16 +00:00
|
|
|
final _closeButton = currentTheme.type == ThemeType.dark
|
|
|
|
? closeButtonImageDarkTheme : closeButtonImage;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
height: 37,
|
2020-11-09 15:01:58 +00:00
|
|
|
width: 37,
|
2020-01-04 19:31:52 +00:00
|
|
|
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-11-11 15:55:18 +00:00
|
|
|
fontFamily: 'Lato',
|
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-12-15 19:30:16 +00:00
|
|
|
final appBarColor = currentTheme.type == ThemeType.dark
|
|
|
|
? 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-12-15 19:30:16 +00:00
|
|
|
final _backgroundColor = currentTheme.type == ThemeType.dark
|
|
|
|
? backgroundDarkColor : backgroundLightColor;
|
2020-12-10 17:53:40 +00:00
|
|
|
|
2020-06-20 07:10:00 +00:00
|
|
|
final root = Scaffold(
|
2020-07-31 15:29:21 +00:00
|
|
|
key: _scaffoldKey,
|
2020-12-10 17:53:40 +00:00
|
|
|
backgroundColor: _backgroundColor,
|
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
|
|
|
}
|
|
|
|
}
|