refactor: base_page improvements and simplify

This commit is contained in:
Rafael Saes 2023-07-03 13:06:18 -03:00
parent e38a6a7190
commit 8c7685c01b
9 changed files with 60 additions and 88 deletions

View file

@ -1,7 +1,6 @@
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/src/widgets/nav_bar.dart';
@ -9,23 +8,23 @@ import 'package:cake_wallet/src/widgets/nav_bar.dart';
enum AppBarStyle { regular, withShadow, transparent }
abstract class BasePage extends StatelessWidget {
BasePage()
: _scaffoldKey = GlobalKey<ScaffoldState>();
BasePage() : _scaffoldKey = GlobalKey<ScaffoldState>();
final GlobalKey<ScaffoldState> _scaffoldKey;
final Image closeButtonImage =
Image.asset('assets/images/close_button.png');
final Image closeButtonImage = Image.asset('assets/images/close_button.png');
final Image closeButtonImageDarkTheme =
Image.asset('assets/images/close_button_dark_theme.png');
Image.asset('assets/images/close_button_dark_theme.png');
String? get title => null;
Color get backgroundLightColor => Colors.white;
Color? get backgroundLightColor => null;
Color get backgroundDarkColor => PaletteDark.backgroundColor;
Color? get backgroundDarkColor => null;
Color? get titleColor => null;
bool get gradientBackground => false;
bool get resizeToAvoidBottomInset => true;
bool get extendBodyBehindAppBar => false;
@ -42,15 +41,39 @@ abstract class BasePage extends StatelessWidget {
void onClose(BuildContext context) => Navigator.of(context).pop();
Color pageBackgroundColor(BuildContext context) =>
(currentTheme.type == ThemeType.dark
? backgroundDarkColor
: backgroundLightColor) ??
(gradientBackground && currentTheme.type == ThemeType.bright
? Colors.transparent
: Theme.of(context).colorScheme.background);
Color? pageIconColor(BuildContext context) =>
titleColor ??
(gradientBackground
? Theme.of(context).primaryTextTheme.titleLarge!.color!
: Theme.of(context).primaryTextTheme.titleLarge!.color!);
Widget closeButton(BuildContext context) => Image.asset(
currentTheme.type == ThemeType.dark
? 'assets/images/close_button_dark_theme.png'
: 'assets/images/close_button.png',
color: pageIconColor(context),
height: 16,
);
Widget backButton(BuildContext context) => Icon(
Icons.arrow_back_ios,
color: pageIconColor(context),
size: 16,
);
Widget? leading(BuildContext context) {
if (ModalRoute.of(context)?.isFirst ?? true) {
return null;
}
final _backButton = Icon(Icons.arrow_back_ios,
color: titleColor ?? Theme.of(context).primaryTextTheme!.titleLarge!.color!,
size: 16,);
return MergeSemantics(
child: SizedBox(
height: 37,
@ -65,7 +88,7 @@ abstract class BasePage extends StatelessWidget {
(states) => Colors.transparent),
),
onPressed: () => onClose(context),
child: _backButton,
child: backButton(context),
),
),
),
@ -83,7 +106,7 @@ abstract class BasePage extends StatelessWidget {
fontWeight: FontWeight.bold,
fontFamily: 'Lato',
color: titleColor ??
Theme.of(context).primaryTextTheme!.titleLarge!.color!),
Theme.of(context).primaryTextTheme.titleLarge!.color!),
);
}
@ -92,8 +115,7 @@ abstract class BasePage extends StatelessWidget {
Widget? floatingActionButton(BuildContext context) => null;
ObstructingPreferredSizeWidget appBar(BuildContext context) {
final appBarColor = currentTheme.type == ThemeType.dark
? backgroundDarkColor : backgroundLightColor;
final appBarColor = pageBackgroundColor(context);
switch (appBarStyle) {
case AppBarStyle.regular:
@ -138,12 +160,9 @@ abstract class BasePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final _backgroundColor = currentTheme.type == ThemeType.dark
? backgroundDarkColor : backgroundLightColor;
final root = Scaffold(
key: _scaffoldKey,
backgroundColor: _backgroundColor,
backgroundColor: pageBackgroundColor(context),
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
extendBodyBehindAppBar: extendBodyBehindAppBar,
endDrawer: endDrawer,

View file

@ -66,11 +66,7 @@ class _DashboardPageView extends BasePage {
final BalancePage balancePage;
@override
Color get backgroundLightColor =>
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
@override
Color get backgroundDarkColor => Colors.transparent;
bool get gradientBackground => true;
@override
Widget Function(BuildContext, Widget) get rootWrapper =>

View file

@ -50,11 +50,11 @@ class AddressPage extends BasePage {
final FocusNode _cryptoAmountFocus;
@override
Color get backgroundLightColor =>
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
bool get gradientBackground => true;
@override
Color get backgroundDarkColor => Colors.transparent;
Color? get titleColor =>
currentTheme.themeData.accentTextTheme.displayMedium!.backgroundColor;
@override
bool get resizeToAvoidBottomInset => false;
@ -63,18 +63,6 @@ class AddressPage extends BasePage {
@override
Widget? leading(BuildContext context) {
final _backButton = Icon(
Icons.arrow_back_ios,
color: Theme.of(context)
.accentTextTheme!
.displayMedium!
.backgroundColor!,
size: 16,
);
final _closeButton = currentTheme.type == ThemeType.dark
? closeButtonImageDarkTheme
: closeButtonImage;
bool isMobileView = ResponsiveLayoutUtil.instance.isMobile;
return MergeSemantics(
@ -91,7 +79,7 @@ class AddressPage extends BasePage {
(states) => Colors.transparent),
),
onPressed: () => onClose(context),
child: !isMobileView ? _closeButton : _backButton,
child: !isMobileView ? closeButton(context) : backButton(context),
),
),
),
@ -100,11 +88,9 @@ class AddressPage extends BasePage {
}
@override
Widget middle(BuildContext context) =>
PresentReceiveOptionPicker(
receiveOptionViewModel: receiveOptionViewModel,
hasWhiteBackground: currentTheme.type == ThemeType.light,
);
Widget middle(BuildContext context) => PresentReceiveOptionPicker(
receiveOptionViewModel: receiveOptionViewModel,
gradientBackground: gradientBackground);
@override
Widget Function(BuildContext, Widget) get rootWrapper =>
@ -127,14 +113,7 @@ class AddressPage extends BasePage {
context: context,
);
},
icon: Icon(
Icons.share,
size: 20,
color: Theme.of(context)
.accentTextTheme!
.displayMedium!
.backgroundColor!,
),
icon: Icon(Icons.share, size: 20, color: pageIconColor(context)),
),
);
}

View file

@ -15,8 +15,8 @@ class BalancePage extends StatelessWidget {
final DashboardViewModel dashboardViewModel;
final SettingsStore settingsStore;
Color get backgroundLightColor =>
settingsStore.currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
@override
bool get gradientBackground => true;
@override
Widget build(BuildContext context) {

View file

@ -10,14 +10,14 @@ import 'package:cake_wallet/generated/i18n.dart';
class PresentReceiveOptionPicker extends StatelessWidget {
PresentReceiveOptionPicker(
{required this.receiveOptionViewModel, this.hasWhiteBackground = false});
{required this.receiveOptionViewModel, this.gradientBackground = false});
final ReceiveOptionViewModel receiveOptionViewModel;
final bool hasWhiteBackground;
final bool gradientBackground;
@override
Widget build(BuildContext context) {
final textIconTheme = hasWhiteBackground
final textIconTheme = gradientBackground
? Theme.of(context)
.accentTextTheme!
.displayMedium!

View file

@ -38,10 +38,7 @@ class IoniaManageCardsPage extends BasePage {
final _searchController = TextEditingController();
@override
Color get backgroundLightColor => currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
@override
Color get backgroundDarkColor => Colors.transparent;
bool get gradientBackground => true;
@override
Color get titleColor => currentTheme.type == ThemeType.bright ? Colors.white : Colors.black;

View file

@ -9,7 +9,6 @@ import 'package:cake_wallet/src/widgets/gradient_background.dart';
import 'package:cake_wallet/src/screens/receive/widgets/anonpay_status_section.dart';
import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart';
import 'package:cake_wallet/src/screens/receive/widgets/copy_link_item.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:device_display_brightness/device_display_brightness.dart';
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart' as qr;
@ -23,11 +22,7 @@ class AnonPayReceivePage extends BasePage {
String get title => S.current.receive;
@override
Color get backgroundLightColor =>
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
@override
Color get backgroundDarkColor => Colors.transparent;
bool get gradientBackground => true;
@override
bool get resizeToAvoidBottomInset => false;

View file

@ -1,7 +1,6 @@
import 'package:cake_wallet/entities/qr_view_data.dart';
import 'package:cake_wallet/src/widgets/gradient_background.dart';
import 'package:cake_wallet/src/screens/receive/widgets/qr_image.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
@ -11,10 +10,7 @@ class FullscreenQRPage extends BasePage {
final QrViewData qrViewData;
@override
Color get backgroundLightColor => currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
@override
Color get backgroundDarkColor => Colors.transparent;
bool get gradientBackground => true;
@override
bool get resizeToAvoidBottomInset => false;

View file

@ -42,11 +42,7 @@ class ReceivePage extends BasePage {
String get title => S.current.receive;
@override
Color get backgroundLightColor =>
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
@override
Color get backgroundDarkColor => Colors.transparent;
bool get gradientBackground => true;
@override
bool get resizeToAvoidBottomInset => false;
@ -65,10 +61,7 @@ class ReceivePage extends BasePage {
fontSize: 18.0,
fontWeight: FontWeight.bold,
fontFamily: 'Lato',
color: Theme.of(context)
.accentTextTheme!
.displayMedium!
.backgroundColor!),
color: pageIconColor(context)),
);
}
@ -98,10 +91,7 @@ class ReceivePage extends BasePage {
icon: Icon(
Icons.share,
size: 20,
color: Theme.of(context)
.accentTextTheme!
.displayMedium!
.backgroundColor!,
color: pageIconColor(context),
),
),
));