2022-11-08 15:49:51 +00:00
|
|
|
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;
|
2024-05-31 14:57:40 +00:00
|
|
|
final Function(BuildContext context)? pushToWidget;
|
|
|
|
final Function(BuildContext context)? pushToNextWidget;
|
|
|
|
final Function(BuildContext context)? popWidget;
|
|
|
|
final Function(BuildContext context)? popNextWidget;
|
2022-11-08 15:49:51 +00:00
|
|
|
|
|
|
|
@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) {
|
2024-05-31 14:57:40 +00:00
|
|
|
widget.pushToWidget!(context);
|
2022-11-08 15:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didPushNext() {
|
|
|
|
if (widget.pushToNextWidget != null) {
|
2024-05-31 14:57:40 +00:00
|
|
|
widget.pushToNextWidget!(context);
|
2022-11-08 15:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didPop() {
|
|
|
|
if (widget.popWidget != null) {
|
2024-05-31 14:57:40 +00:00
|
|
|
widget.popWidget!(context);
|
2022-11-08 15:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didPopNext() {
|
|
|
|
if (widget.popNextWidget != null) {
|
2024-05-31 14:57:40 +00:00
|
|
|
widget.popNextWidget!(context);
|
2022-11-08 15:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => widget.child;
|
|
|
|
}
|