cake_wallet/lib/src/screens/base_page.dart

155 lines
4.6 KiB
Dart
Raw Normal View History

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';
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>();
2020-09-28 15:47:43 +00:00
final GlobalKey<ScaffoldState> _scaffoldKey;
final Image closeButtonImage =
Image.asset('assets/images/close_button.png');
final Image closeButtonImageDarkTheme =
Image.asset('assets/images/close_button_dark_theme.png');
2022-10-12 17:09:57 +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;
2022-10-12 17:09:57 +00:00
Color? get titleColor => null;
2020-06-20 07:10:00 +00:00
bool get resizeToAvoidBottomInset => true;
2020-06-20 07:10:00 +00:00
bool get extendBodyBehindAppBar => false;
2022-10-12 17:09:57 +00:00
Widget? get endDrawer => null;
2020-01-04 19:31:52 +00:00
AppBarStyle get appBarStyle => AppBarStyle.regular;
2022-10-12 17:09:57 +00:00
Widget Function(BuildContext, Widget)? get rootWrapper => null;
2020-06-20 07:10:00 +00:00
ThemeBase get currentTheme => getIt.get<SettingsStore>().currentTheme;
2020-01-04 19:31:52 +00:00
2022-10-12 17:09:57 +00:00
void onOpenEndDrawer() => _scaffoldKey.currentState!.openEndDrawer();
2020-01-04 19:31:52 +00:00
void onClose(BuildContext context) => Navigator.of(context).pop();
2022-10-12 17:09:57 +00:00
Widget? leading(BuildContext context) {
if (ModalRoute.of(context)?.isFirst ?? true) {
2020-01-04 19:31:52 +00:00
return null;
}
final _backButton = Icon(Icons.arrow_back_ios,
2022-10-12 17:09:57 +00:00
color: titleColor ?? Theme.of(context).primaryTextTheme!.headline6!.color!,
size: 16,);
final _closeButton = currentTheme.type == ThemeType.dark
? closeButtonImageDarkTheme : closeButtonImage;
2020-01-04 19:31:52 +00:00
return SizedBox(
height: 37,
width: 37,
2020-01-04 19:31:52 +00:00
child: ButtonTheme(
minWidth: double.minPositive,
2022-10-12 17:09:57 +00:00
child: TextButton(
// FIX-ME: Style
//highlightColor: Colors.transparent,
//splashColor: Colors.transparent,
//padding: EdgeInsets.all(0),
2020-01-04 19:31:52 +00:00
onPressed: () => onClose(context),
child: isModalBackButton ? _closeButton : _backButton),
),
);
}
2022-10-12 17:09:57 +00:00
Widget? middle(BuildContext context) {
2020-01-04 19:31:52 +00:00
return title == null
? null
: Text(
2022-10-12 17:09:57 +00:00
title!,
2020-01-04 19:31:52 +00:00
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
fontFamily: 'Lato',
color: titleColor ??
2022-10-12 17:09:57 +00:00
Theme.of(context).primaryTextTheme!.headline6!.color!),
2020-01-04 19:31:52 +00:00
);
}
2022-10-12 17:09:57 +00:00
Widget? trailing(BuildContext context) => null;
2020-01-04 19:31:52 +00:00
2022-10-12 17:09:57 +00:00
Widget? floatingActionButton(BuildContext context) => null;
2020-01-04 19:31:52 +00:00
2020-01-08 12:26:34 +00:00
ObstructingPreferredSizeWidget appBar(BuildContext context) {
final appBarColor = currentTheme.type == ThemeType.dark
? backgroundDarkColor : backgroundLightColor;
2020-01-04 19:31:52 +00:00
switch (appBarStyle) {
case AppBarStyle.regular:
2022-10-12 17:09:57 +00:00
// FIX-ME: NavBar no context
2020-01-04 19:31:52 +00:00
return NavBar(
2022-10-12 17:09:57 +00:00
// context: context,
2020-01-04 19:31:52 +00:00
leading: leading(context),
middle: middle(context),
trailing: trailing(context),
backgroundColor: appBarColor);
2020-01-04 19:31:52 +00:00
case AppBarStyle.withShadow:
2022-10-12 17:09:57 +00:00
// FIX-ME: NavBar no context
2020-01-04 19:31:52 +00:00
return NavBar.withShadow(
2022-10-12 17:09:57 +00:00
// context: context,
2020-01-04 19:31:52 +00:00
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:
2022-10-12 17:09:57 +00:00
// FIX-ME: NavBar no context
2020-01-04 19:31:52 +00:00
return NavBar(
2022-10-12 17:09:57 +00:00
// context: context,
2020-01-04 19:31:52 +00:00
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) {
final _backgroundColor = currentTheme.type == ThemeType.dark
? backgroundDarkColor : backgroundLightColor;
2020-06-20 07:10:00 +00:00
final root = Scaffold(
key: _scaffoldKey,
backgroundColor: _backgroundColor,
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
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
}
}