mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 20:19:25 +00:00
refactor: base_page improvements and simplify
This commit is contained in:
parent
e38a6a7190
commit
8c7685c01b
9 changed files with 60 additions and 88 deletions
|
@ -1,7 +1,6 @@
|
||||||
import 'package:cake_wallet/themes/theme_base.dart';
|
import 'package:cake_wallet/themes/theme_base.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:cake_wallet/palette.dart';
|
|
||||||
import 'package:cake_wallet/di.dart';
|
import 'package:cake_wallet/di.dart';
|
||||||
import 'package:cake_wallet/store/settings_store.dart';
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:cake_wallet/src/widgets/nav_bar.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 }
|
enum AppBarStyle { regular, withShadow, transparent }
|
||||||
|
|
||||||
abstract class BasePage extends StatelessWidget {
|
abstract class BasePage extends StatelessWidget {
|
||||||
BasePage()
|
BasePage() : _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
: _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey;
|
final GlobalKey<ScaffoldState> _scaffoldKey;
|
||||||
|
|
||||||
final Image closeButtonImage =
|
final Image closeButtonImage = Image.asset('assets/images/close_button.png');
|
||||||
Image.asset('assets/images/close_button.png');
|
|
||||||
final Image closeButtonImageDarkTheme =
|
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;
|
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;
|
Color? get titleColor => null;
|
||||||
|
|
||||||
|
bool get gradientBackground => false;
|
||||||
|
|
||||||
bool get resizeToAvoidBottomInset => true;
|
bool get resizeToAvoidBottomInset => true;
|
||||||
|
|
||||||
bool get extendBodyBehindAppBar => false;
|
bool get extendBodyBehindAppBar => false;
|
||||||
|
@ -42,15 +41,39 @@ abstract class BasePage extends StatelessWidget {
|
||||||
|
|
||||||
void onClose(BuildContext context) => Navigator.of(context).pop();
|
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) {
|
Widget? leading(BuildContext context) {
|
||||||
if (ModalRoute.of(context)?.isFirst ?? true) {
|
if (ModalRoute.of(context)?.isFirst ?? true) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final _backButton = Icon(Icons.arrow_back_ios,
|
|
||||||
color: titleColor ?? Theme.of(context).primaryTextTheme!.titleLarge!.color!,
|
|
||||||
size: 16,);
|
|
||||||
|
|
||||||
return MergeSemantics(
|
return MergeSemantics(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 37,
|
height: 37,
|
||||||
|
@ -65,7 +88,7 @@ abstract class BasePage extends StatelessWidget {
|
||||||
(states) => Colors.transparent),
|
(states) => Colors.transparent),
|
||||||
),
|
),
|
||||||
onPressed: () => onClose(context),
|
onPressed: () => onClose(context),
|
||||||
child: _backButton,
|
child: backButton(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -83,7 +106,7 @@ abstract class BasePage extends StatelessWidget {
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontFamily: 'Lato',
|
fontFamily: 'Lato',
|
||||||
color: titleColor ??
|
color: titleColor ??
|
||||||
Theme.of(context).primaryTextTheme!.titleLarge!.color!),
|
Theme.of(context).primaryTextTheme.titleLarge!.color!),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +115,8 @@ abstract class BasePage extends StatelessWidget {
|
||||||
Widget? floatingActionButton(BuildContext context) => null;
|
Widget? floatingActionButton(BuildContext context) => null;
|
||||||
|
|
||||||
ObstructingPreferredSizeWidget appBar(BuildContext context) {
|
ObstructingPreferredSizeWidget appBar(BuildContext context) {
|
||||||
final appBarColor = currentTheme.type == ThemeType.dark
|
final appBarColor = pageBackgroundColor(context);
|
||||||
? backgroundDarkColor : backgroundLightColor;
|
|
||||||
|
|
||||||
switch (appBarStyle) {
|
switch (appBarStyle) {
|
||||||
case AppBarStyle.regular:
|
case AppBarStyle.regular:
|
||||||
// FIX-ME: NavBar no context
|
// FIX-ME: NavBar no context
|
||||||
|
@ -138,12 +160,9 @@ abstract class BasePage extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final _backgroundColor = currentTheme.type == ThemeType.dark
|
|
||||||
? backgroundDarkColor : backgroundLightColor;
|
|
||||||
|
|
||||||
final root = Scaffold(
|
final root = Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
backgroundColor: _backgroundColor,
|
backgroundColor: pageBackgroundColor(context),
|
||||||
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
|
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
|
||||||
extendBodyBehindAppBar: extendBodyBehindAppBar,
|
extendBodyBehindAppBar: extendBodyBehindAppBar,
|
||||||
endDrawer: endDrawer,
|
endDrawer: endDrawer,
|
||||||
|
|
|
@ -66,11 +66,7 @@ class _DashboardPageView extends BasePage {
|
||||||
final BalancePage balancePage;
|
final BalancePage balancePage;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundLightColor =>
|
bool get gradientBackground => true;
|
||||||
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Color get backgroundDarkColor => Colors.transparent;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget Function(BuildContext, Widget) get rootWrapper =>
|
Widget Function(BuildContext, Widget) get rootWrapper =>
|
||||||
|
|
|
@ -50,11 +50,11 @@ class AddressPage extends BasePage {
|
||||||
final FocusNode _cryptoAmountFocus;
|
final FocusNode _cryptoAmountFocus;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundLightColor =>
|
bool get gradientBackground => true;
|
||||||
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundDarkColor => Colors.transparent;
|
Color? get titleColor =>
|
||||||
|
currentTheme.themeData.accentTextTheme.displayMedium!.backgroundColor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get resizeToAvoidBottomInset => false;
|
bool get resizeToAvoidBottomInset => false;
|
||||||
|
@ -63,18 +63,6 @@ class AddressPage extends BasePage {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget? leading(BuildContext context) {
|
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;
|
bool isMobileView = ResponsiveLayoutUtil.instance.isMobile;
|
||||||
|
|
||||||
return MergeSemantics(
|
return MergeSemantics(
|
||||||
|
@ -91,7 +79,7 @@ class AddressPage extends BasePage {
|
||||||
(states) => Colors.transparent),
|
(states) => Colors.transparent),
|
||||||
),
|
),
|
||||||
onPressed: () => onClose(context),
|
onPressed: () => onClose(context),
|
||||||
child: !isMobileView ? _closeButton : _backButton,
|
child: !isMobileView ? closeButton(context) : backButton(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -100,11 +88,9 @@ class AddressPage extends BasePage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget middle(BuildContext context) =>
|
Widget middle(BuildContext context) => PresentReceiveOptionPicker(
|
||||||
PresentReceiveOptionPicker(
|
receiveOptionViewModel: receiveOptionViewModel,
|
||||||
receiveOptionViewModel: receiveOptionViewModel,
|
gradientBackground: gradientBackground);
|
||||||
hasWhiteBackground: currentTheme.type == ThemeType.light,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget Function(BuildContext, Widget) get rootWrapper =>
|
Widget Function(BuildContext, Widget) get rootWrapper =>
|
||||||
|
@ -127,14 +113,7 @@ class AddressPage extends BasePage {
|
||||||
context: context,
|
context: context,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(Icons.share, size: 20, color: pageIconColor(context)),
|
||||||
Icons.share,
|
|
||||||
size: 20,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.accentTextTheme!
|
|
||||||
.displayMedium!
|
|
||||||
.backgroundColor!,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ class BalancePage extends StatelessWidget {
|
||||||
final DashboardViewModel dashboardViewModel;
|
final DashboardViewModel dashboardViewModel;
|
||||||
final SettingsStore settingsStore;
|
final SettingsStore settingsStore;
|
||||||
|
|
||||||
Color get backgroundLightColor =>
|
@override
|
||||||
settingsStore.currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
bool get gradientBackground => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
|
@ -10,14 +10,14 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
|
||||||
class PresentReceiveOptionPicker extends StatelessWidget {
|
class PresentReceiveOptionPicker extends StatelessWidget {
|
||||||
PresentReceiveOptionPicker(
|
PresentReceiveOptionPicker(
|
||||||
{required this.receiveOptionViewModel, this.hasWhiteBackground = false});
|
{required this.receiveOptionViewModel, this.gradientBackground = false});
|
||||||
|
|
||||||
final ReceiveOptionViewModel receiveOptionViewModel;
|
final ReceiveOptionViewModel receiveOptionViewModel;
|
||||||
final bool hasWhiteBackground;
|
final bool gradientBackground;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final textIconTheme = hasWhiteBackground
|
final textIconTheme = gradientBackground
|
||||||
? Theme.of(context)
|
? Theme.of(context)
|
||||||
.accentTextTheme!
|
.accentTextTheme!
|
||||||
.displayMedium!
|
.displayMedium!
|
||||||
|
|
|
@ -38,10 +38,7 @@ class IoniaManageCardsPage extends BasePage {
|
||||||
final _searchController = TextEditingController();
|
final _searchController = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundLightColor => currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
bool get gradientBackground => true;
|
||||||
|
|
||||||
@override
|
|
||||||
Color get backgroundDarkColor => Colors.transparent;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get titleColor => currentTheme.type == ThemeType.bright ? Colors.white : Colors.black;
|
Color get titleColor => currentTheme.type == ThemeType.bright ? Colors.white : Colors.black;
|
||||||
|
|
|
@ -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/anonpay_status_section.dart';
|
||||||
import 'package:cake_wallet/src/screens/receive/widgets/qr_image.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/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:device_display_brightness/device_display_brightness.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:qr_flutter/qr_flutter.dart' as qr;
|
import 'package:qr_flutter/qr_flutter.dart' as qr;
|
||||||
|
@ -23,11 +22,7 @@ class AnonPayReceivePage extends BasePage {
|
||||||
String get title => S.current.receive;
|
String get title => S.current.receive;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundLightColor =>
|
bool get gradientBackground => true;
|
||||||
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Color get backgroundDarkColor => Colors.transparent;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get resizeToAvoidBottomInset => false;
|
bool get resizeToAvoidBottomInset => false;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import 'package:cake_wallet/entities/qr_view_data.dart';
|
import 'package:cake_wallet/entities/qr_view_data.dart';
|
||||||
import 'package:cake_wallet/src/widgets/gradient_background.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/src/screens/receive/widgets/qr_image.dart';
|
||||||
import 'package:cake_wallet/themes/theme_base.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||||
|
|
||||||
|
@ -11,10 +10,7 @@ class FullscreenQRPage extends BasePage {
|
||||||
final QrViewData qrViewData;
|
final QrViewData qrViewData;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundLightColor => currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
bool get gradientBackground => true;
|
||||||
|
|
||||||
@override
|
|
||||||
Color get backgroundDarkColor => Colors.transparent;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get resizeToAvoidBottomInset => false;
|
bool get resizeToAvoidBottomInset => false;
|
||||||
|
|
|
@ -42,11 +42,7 @@ class ReceivePage extends BasePage {
|
||||||
String get title => S.current.receive;
|
String get title => S.current.receive;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color get backgroundLightColor =>
|
bool get gradientBackground => true;
|
||||||
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Color get backgroundDarkColor => Colors.transparent;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get resizeToAvoidBottomInset => false;
|
bool get resizeToAvoidBottomInset => false;
|
||||||
|
@ -65,10 +61,7 @@ class ReceivePage extends BasePage {
|
||||||
fontSize: 18.0,
|
fontSize: 18.0,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontFamily: 'Lato',
|
fontFamily: 'Lato',
|
||||||
color: Theme.of(context)
|
color: pageIconColor(context)),
|
||||||
.accentTextTheme!
|
|
||||||
.displayMedium!
|
|
||||||
.backgroundColor!),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +91,7 @@ class ReceivePage extends BasePage {
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.share,
|
Icons.share,
|
||||||
size: 20,
|
size: 20,
|
||||||
color: Theme.of(context)
|
color: pageIconColor(context),
|
||||||
.accentTextTheme!
|
|
||||||
.displayMedium!
|
|
||||||
.backgroundColor!,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in a new issue