2024-06-13 15:42:39 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2024-06-13 17:00:08 +02:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:simplecloudnotifier/state/app_bar_state.dart';
|
2024-06-13 15:42:39 +02:00
|
|
|
|
|
|
|
class Navi {
|
2024-06-13 17:00:08 +02:00
|
|
|
static final SCNRouteObserver routeObserver = SCNRouteObserver();
|
2024-06-15 15:56:50 +02:00
|
|
|
static final RouteObserver<ModalRoute<void>> modalRouteObserver = RouteObserver<ModalRoute<void>>();
|
2024-06-13 17:00:08 +02:00
|
|
|
|
2024-06-13 15:42:39 +02:00
|
|
|
static void push<T extends Widget>(BuildContext context, T Function() builder) {
|
2024-06-13 17:00:08 +02:00
|
|
|
Provider.of<AppBarState>(context, listen: false).setLoadingIndeterminate(false);
|
|
|
|
|
2024-06-13 15:42:39 +02:00
|
|
|
Navigator.push(context, MaterialPageRoute<T>(builder: (context) => builder()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void popToRoot(BuildContext context) {
|
2024-06-13 17:00:08 +02:00
|
|
|
Provider.of<AppBarState>(context, listen: false).setLoadingIndeterminate(false);
|
|
|
|
|
2024-06-13 15:42:39 +02:00
|
|
|
Navigator.popUntil(context, (route) => route.isFirst);
|
|
|
|
}
|
|
|
|
}
|
2024-06-13 17:00:08 +02:00
|
|
|
|
|
|
|
class SCNRouteObserver extends RouteObserver<PageRoute<dynamic>> {
|
|
|
|
@override
|
|
|
|
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
|
|
super.didPush(route, previousRoute);
|
|
|
|
if (route is PageRoute) {
|
|
|
|
AppBarState().setLoadingIndeterminate(false);
|
|
|
|
|
|
|
|
print('[SCNRouteObserver] .didPush()');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
|
|
|
|
super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
|
|
|
|
if (newRoute is PageRoute) {
|
|
|
|
AppBarState().setLoadingIndeterminate(false);
|
|
|
|
|
|
|
|
print('[SCNRouteObserver] .didReplace()');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
|
|
|
|
super.didPop(route, previousRoute);
|
|
|
|
if (previousRoute is PageRoute && route is PageRoute) {
|
|
|
|
AppBarState().setLoadingIndeterminate(false);
|
|
|
|
|
|
|
|
print('[SCNRouteObserver] .didPop()');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|