cake_wallet/lib/src/screens/base_page.dart

139 lines
4.3 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/src/widgets/nav_bar.dart';
import 'package:provider/provider.dart';
import 'package:cake_wallet/themes.dart';
import 'package:cake_wallet/theme_changer.dart';
import 'package:cake_wallet/palette.dart';
2020-01-04 19:31:52 +00:00
enum AppBarStyle { regular, withShadow }
abstract class BasePage extends StatelessWidget {
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
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;
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
2020-01-04 19:31:52 +00:00
final _closeButtonImage = Image.asset('assets/images/close_button.png');
final _closeButtonImageDarkTheme =
Image.asset('assets/images/close_button_dark_theme.png');
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',
color: titleColor ?? Theme.of(context).primaryTextTheme.title.color);
2020-01-08 12:26:34 +00:00
final _themeChanger = Provider.of<ThemeChanger>(context);
final _closeButton = _themeChanger.getTheme() == Themes.darkTheme
? _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,
color: titleColor ??
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-01-04 19:31:52 +00:00
final _themeChanger = Provider.of<ThemeChanger>(context);
final _isDarkTheme = _themeChanger.getTheme() == Themes.darkTheme;
switch (appBarStyle) {
case AppBarStyle.regular:
return NavBar(
context: context,
leading: leading(context),
middle: middle(context),
trailing: trailing(context),
2020-06-20 07:10:00 +00:00
backgroundColor:
_isDarkTheme ? backgroundDarkColor : backgroundLightColor);
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-06-20 07:10:00 +00:00
backgroundColor:
_isDarkTheme ? backgroundDarkColor : backgroundLightColor);
2020-01-04 19:31:52 +00:00
default:
return NavBar(
context: context,
leading: leading(context),
middle: middle(context),
trailing: trailing(context),
2020-06-20 07:10:00 +00:00
backgroundColor:
_isDarkTheme ? backgroundDarkColor : backgroundLightColor);
2020-01-04 19:31:52 +00:00
}
}
Widget body(BuildContext context);
@override
Widget build(BuildContext context) {
final _themeChanger = Provider.of<ThemeChanger>(context);
final _isDarkTheme = _themeChanger.getTheme() == Themes.darkTheme;
2020-06-20 07:10:00 +00:00
final root = Scaffold(
key: _scaffoldKey,
2020-06-20 07:10:00 +00:00
backgroundColor:
_isDarkTheme ? backgroundDarkColor : backgroundLightColor,
2020-01-04 19:31:52 +00:00
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding,
endDrawer: endDrawer,
2020-01-04 19:31:52 +00:00
appBar: appBar(context),
2020-07-06 20:09:03 +00:00
body: body(context), //SafeArea(child: ),
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
}
}