refactor: create QRCodeTheme

This commit is contained in:
Rafael Saes 2023-07-05 14:59:14 -03:00
parent 3f51f22982
commit 74abc02a4f
9 changed files with 54 additions and 21 deletions

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/entities/contact_base.dart';
import 'package:cake_wallet/themes/extensions/qr_code_theme.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/themes/extensions/exchange_page_theme.dart';
@ -177,7 +178,7 @@ class ExchangeCardState extends State<ExchangeCard> {
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Theme.of(context).textTheme!.headlineSmall!.color!),
color: Theme.of(context).extension<QRCodeTheme>()!.qrCodeColor),
)
],
),

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/themes/extensions/qr_code_theme.dart';
import 'package:cake_wallet/src/widgets/check_box_picker.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:flutter/material.dart';
@ -49,10 +50,7 @@ class PresentProviderPicker extends StatelessWidget {
style: TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.textTheme!
.headlineSmall!
.color!)))
color: Theme.of(context).extension<QRCodeTheme>()!.qrCodeColor)))
],
),
SizedBox(width: 5),

View file

@ -9,6 +9,7 @@ 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/extensions/qr_code_theme.dart';
import 'package:device_display_brightness/device_display_brightness.dart';
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart' as qr;
@ -68,7 +69,7 @@ class AnonPayReceivePage extends BasePage {
style: TextStyle(
fontSize: 10.0,
fontWeight: FontWeight.w500,
color: Theme.of(context).textTheme!.headlineSmall!.color!),
color: Theme.of(context).extension<QRCodeTheme>()!.qrCodeColor),
)
],
);

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/entities/qr_view_data.dart';
import 'package:cake_wallet/themes/extensions/qr_code_theme.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/exchange/widgets/currency_picker.dart';
import 'package:cake_wallet/src/screens/receive/widgets/currency_input_field.dart';
@ -36,7 +37,7 @@ class QRWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final copyImage = Image.asset('assets/images/copy_address.png',
color: Theme.of(context).textTheme!.titleMedium!.decorationColor!);
color: Theme.of(context).extension<QRCodeTheme>()!.qrWidgetCopyButtonColor);
return Column(
mainAxisSize: MainAxisSize.min,

View file

@ -105,6 +105,11 @@ class BrightTheme extends LightTheme {
amountHintTextColor: Colors.white,
);
@override
QRCodeTheme get qrCodeTheme => super
.qrCodeTheme
.copyWith(qrWidgetCopyButtonColor: Colors.white.withOpacity(0.4));
@override
ThemeData get themeData => super.themeData.copyWith(
indicatorColor: Colors.white.withOpacity(0.5), // page indicator
@ -121,10 +126,6 @@ class BrightTheme extends LightTheme {
decorationColor:
Colors.white.withOpacity(0.4), // copy button (qr widget)
),
// headline -> headlineSmall
headlineSmall: TextStyle(
color: Colors.white, // qr code
),
),
);
}

View file

@ -189,6 +189,11 @@ class DarkTheme extends ThemeBase {
amountBottomBorderColor: PaletteDark.darkGrey,
amountHintTextColor: PaletteDark.cyanBlue);
@override
QRCodeTheme get qrCodeTheme => QRCodeTheme(
qrCodeColor: PaletteDark.lightBlueGrey,
qrWidgetCopyButtonColor: PaletteDark.lightBlueGrey);
@override
ThemeData get themeData => super.themeData.copyWith(
indicatorColor: PaletteDark.cyanBlue, // page indicator
@ -206,11 +211,6 @@ class DarkTheme extends ThemeBase {
// subhead -> titleMedium
titleMedium: TextStyle(
color: PaletteDark.nightBlue, // address button border
decorationColor: PaletteDark.lightBlueGrey, // copy button (qr widget)
),
// headline -> headlineSmall
headlineSmall: TextStyle(
color: PaletteDark.lightBlueGrey, // qr code
),
),
);

View file

@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
class QRCodeTheme extends ThemeExtension<QRCodeTheme> {
final Color qrCodeColor;
final Color qrWidgetCopyButtonColor;
QRCodeTheme(
{required this.qrCodeColor, required this.qrWidgetCopyButtonColor});
@override
QRCodeTheme copyWith({Color? qrCodeColor, Color? qrWidgetCopyButtonColor}) =>
QRCodeTheme(
qrCodeColor: qrCodeColor ?? this.qrCodeColor,
qrWidgetCopyButtonColor:
qrWidgetCopyButtonColor ?? this.qrWidgetCopyButtonColor);
@override
QRCodeTheme lerp(ThemeExtension<QRCodeTheme>? other, double t) {
if (other is! QRCodeTheme) {
return this;
}
return QRCodeTheme(
qrCodeColor: Color.lerp(qrCodeColor, other.qrCodeColor, t)!,
qrWidgetCopyButtonColor: Color.lerp(
qrWidgetCopyButtonColor, other.qrWidgetCopyButtonColor, t)!);
}
}

View file

@ -191,6 +191,11 @@ class LightTheme extends ThemeBase {
amountBottomBorderColor: Palette.darkBlueCraiola,
amountHintTextColor: Palette.darkBlueCraiola);
@override
QRCodeTheme get qrCodeTheme => QRCodeTheme(
qrCodeColor: Colors.white,
qrWidgetCopyButtonColor: PaletteDark.lightBlueGrey);
@override
ThemeData get themeData => super.themeData.copyWith(
indicatorColor:
@ -209,11 +214,6 @@ class LightTheme extends ThemeBase {
// subhead -> titleMedium
titleMedium: TextStyle(
color: Palette.blueAlice, // address button border
decorationColor: PaletteDark.lightBlueGrey, // copy button (qr widget)
),
// headline -> headlineSmall
headlineSmall: TextStyle(
color: Colors.white, // qr code
),
),
);

View file

@ -104,6 +104,8 @@ abstract class ThemeBase {
ReceivePageTheme get receivePageTheme;
QRCodeTheme get qrCodeTheme;
ThemeData get themeData => generatedThemeData.copyWith(
primaryColor: primaryColor,
cardColor: containerColor,
@ -133,6 +135,7 @@ abstract class ThemeBase {
cakeTextTheme,
accountListTheme,
receivePageTheme,
qrCodeTheme,
],
scrollbarTheme: ScrollbarThemeData(
thumbColor: MaterialStateProperty.all(scrollbarTheme.thumbColor),