Merge pull request #608 from cake-tech/CW-167-Custom-redeem-screens-fix

CW-258 fix increasing brightness
This commit is contained in:
Omar Hatem 2022-12-19 16:04:36 +02:00 committed by GitHub
commit 501e62829b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 7 deletions

View file

@ -41,6 +41,7 @@ import 'package:cake_wallet/wallet_type_utils.dart';
final navigatorKey = GlobalKey<NavigatorState>();
final rootKey = GlobalKey<RootState>();
final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
Future<void> main() async {
try {
@ -279,6 +280,7 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
navigatorKey: navigatorKey,
authService: authService,
child: MaterialApp(
navigatorObservers: [routeObserver],
navigatorKey: navigatorKey,
debugShowCheckedModeBanner: false,
theme: settingsStore.theme,

View file

@ -11,6 +11,7 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
import 'package:cake_wallet/typography.dart';
import 'package:cake_wallet/utils/show_bar.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/utils/route_aware.dart';
import 'package:cake_wallet/view_model/ionia/ionia_gift_card_details_view_model.dart';
import 'package:device_display_brightness/device_display_brightness.dart';
import 'package:flutter/material.dart';
@ -47,10 +48,7 @@ class IoniaGiftCardDetailPage extends BasePage {
//highlightColor: Colors.transparent,
//splashColor: Colors.transparent,
//padding: EdgeInsets.all(0),
onPressed: () {
onClose(context);
DeviceDisplayBrightness.setBrightness(viewModel.brightness);
},
onPressed: ()=> onClose(context),
child: _backButton),
),
),
@ -68,7 +66,6 @@ class IoniaGiftCardDetailPage extends BasePage {
@override
Widget body(BuildContext context) {
viewModel.increaseBrightness();
reaction((_) => viewModel.redeemState, (ExecutionState state) {
if (state is FailureState) {
WidgetsBinding.instance.addPostFrameCallback((_) {
@ -85,7 +82,12 @@ class IoniaGiftCardDetailPage extends BasePage {
}
});
return ScrollableWithBottomSection(
return RouteAwareWidget(
pushToWidget: ()=> viewModel.increaseBrightness(),
pushToNextWidget: ()=> DeviceDisplayBrightness.setBrightness(viewModel.brightness),
popNextWidget: ()=> viewModel.increaseBrightness(),
popWidget: ()=> DeviceDisplayBrightness.setBrightness(viewModel.brightness),
child: ScrollableWithBottomSection(
contentPadding: EdgeInsets.all(24),
content: Column(
children: [
@ -164,7 +166,7 @@ class IoniaGiftCardDetailPage extends BasePage {
},
),
),
);
));
}
Widget buildIoniaTile(BuildContext context, {required String title, required String subTitle}) {

View file

@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
import 'package:cake_wallet/main.dart';
class RouteAwareWidget extends StatefulWidget {
RouteAwareWidget(
{required this.child,
this.pushToWidget,
this.pushToNextWidget,
this.popWidget,
this.popNextWidget});
final Widget child;
final Function()? pushToWidget;
final Function()? pushToNextWidget;
final Function()? popWidget;
final Function()? popNextWidget;
@override
State<RouteAwareWidget> createState() => RouteAwareWidgetState();
}
class RouteAwareWidgetState extends State<RouteAwareWidget> with RouteAware {
@override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute);
}
@override
void dispose() {
routeObserver.unsubscribe(this);
super.dispose();
}
@override
void didPush() {
if (widget.pushToWidget != null) {
widget.pushToWidget!();
}
}
@override
void didPushNext() {
if (widget.pushToNextWidget != null) {
widget.pushToNextWidget!();
}
}
@override
void didPop() {
if (widget.popWidget != null) {
widget.popWidget!();
}
}
@override
void didPopNext() {
if (widget.popNextWidget != null) {
widget.popNextWidget!();
}
}
@override
Widget build(BuildContext context) => widget.child;
}