fix increasing brightness
brightness decreases after leaving "gift card barcode screen"
Serhii committed
Nov 8, 2022 at 17:49 UTC
dfb52223e02ba2c727c8f2561ea6bf388535a349
3 files changed
+76
-7
lib/main.dart
+2
@@ -40,6 +40,7 @@ import 'package:cake_wallet/wallet_type_utils.dart';
40
41
final navigatorKey = GlobalKey<NavigatorState>();
42
final rootKey = GlobalKey<RootState>();
43
+final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
44
45
Future<void> main() async {
46
try {
@@ -282,6 +283,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
283
authenticationStore: authenticationStore,
284
navigatorKey: navigatorKey,
285
child: MaterialApp(
286
+ navigatorObservers: [routeObserver],
287
navigatorKey: navigatorKey,
288
debugShowCheckedModeBanner: false,
289
theme: settingsStore.theme,
lib/src/screens/ionia/cards/ionia_gift_card_detail_page.dart
+9
-7
@@ -11,6 +11,7 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
11
import 'package:cake_wallet/typography.dart';
12
import 'package:cake_wallet/utils/show_bar.dart';
13
import 'package:cake_wallet/utils/show_pop_up.dart';
14
+import 'package:cake_wallet/utils/route_aware.dart';
15
import 'package:cake_wallet/view_model/ionia/ionia_gift_card_details_view_model.dart';
16
import 'package:device_display_brightness/device_display_brightness.dart';
17
import 'package:flutter/material.dart';
@@ -47,10 +48,7 @@ class IoniaGiftCardDetailPage extends BasePage {
48
//highlightColor: Colors.transparent,
49
//splashColor: Colors.transparent,
50
//padding: EdgeInsets.all(0),
50
- onPressed: () {
51
- onClose(context);
52
- DeviceDisplayBrightness.setBrightness(viewModel.brightness);
53
- },
51
+ onPressed: ()=> onClose(context),
52
child: _backButton),
53
),
54
),
@@ -67,7 +65,6 @@ class IoniaGiftCardDetailPage extends BasePage {
65
66
@override
67
Widget body(BuildContext context) {
70
- viewModel.increaseBrightness();
68
reaction((_) => viewModel.redeemState, (ExecutionState state) {
69
if (state is FailureState) {
70
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -84,7 +81,12 @@ class IoniaGiftCardDetailPage extends BasePage {
81
}
82
});
83
87
- return ScrollableWithBottomSection(
84
+ return RouteAwareWidget(
85
+ pushToWidget: ()=> viewModel.increaseBrightness(),
86
+ pushToNextWidget: ()=> DeviceDisplayBrightness.setBrightness(viewModel.brightness),
87
+ popNextWidget: ()=> viewModel.increaseBrightness(),
88
+ popWidget: ()=> DeviceDisplayBrightness.setBrightness(viewModel.brightness),
89
+ child: ScrollableWithBottomSection(
90
contentPadding: EdgeInsets.all(24),
91
content: Column(
92
children: [
@@ -163,7 +165,7 @@ class IoniaGiftCardDetailPage extends BasePage {
165
},
166
),
167
),
166
- );
168
+ ));
169
}
170
171
Widget buildIoniaTile(BuildContext context, {required String title, required String subTitle}) {
lib/utils/route_aware.dart
new
+65
@@ -0,0 +1,65 @@
1
+import 'package:flutter/material.dart';
2
+import 'package:cake_wallet/main.dart';
3
+
4
+class RouteAwareWidget extends StatefulWidget {
5
+ RouteAwareWidget(
6
+ {required this.child,
7
+ this.pushToWidget,
8
+ this.pushToNextWidget,
9
+ this.popWidget,
10
+ this.popNextWidget});
11
+
12
+ final Widget child;
13
+ final Function()? pushToWidget;
14
+ final Function()? pushToNextWidget;
15
+ final Function()? popWidget;
16
+ final Function()? popNextWidget;
17
+
18
+ @override
19
+ State<RouteAwareWidget> createState() => RouteAwareWidgetState();
20
+}
21
+
22
+class RouteAwareWidgetState extends State<RouteAwareWidget> with RouteAware {
23
+ @override
24
+ void didChangeDependencies() {
25
+ super.didChangeDependencies();
26
+ routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute);
27
+ }
28
+
29
+ @override
30
+ void dispose() {
31
+ routeObserver.unsubscribe(this);
32
+ super.dispose();
33
+ }
34
+
35
+ @override
36
+ void didPush() {
37
+ if (widget.pushToWidget != null) {
38
+ widget.pushToWidget!();
39
+ }
40
+ }
41
+
42
+ @override
43
+ void didPushNext() {
44
+ if (widget.pushToNextWidget != null) {
45
+ widget.pushToNextWidget!();
46
+ }
47
+ }
48
+
49
+ @override
50
+ void didPop() {
51
+ if (widget.popWidget != null) {
52
+ widget.popWidget!();
53
+ }
54
+ }
55
+
56
+ @override
57
+ void didPopNext() {
58
+ if (widget.popNextWidget != null) {
59
+ widget.popNextWidget!();
60
+ }
61
+ }
62
+
63
+ @override
64
+ Widget build(BuildContext context) => widget.child;
65
+}