pikapika/lib/basic/Navigatior.dart

47 lines
976 B
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
import 'dart:async';
import 'package:flutter/material.dart';
final RouteObserver<ModalRoute<void>> routeObserver =
RouteObserver<ModalRoute<void>>();
Future<dynamic> navPushOrReplace(
BuildContext context, WidgetBuilder builder) async {
if (_depth < _depthMax) {
return Navigator.push(
context,
MaterialPageRoute(builder: builder),
);
} else {
return Navigator.pushReplacement(
context,
MaterialPageRoute(builder: builder),
);
}
}
var navigatorObserver = _NavigatorObserver();
const _depthMax = 15;
var _depth = 0;
int currentDepth() {
return _depth;
}
class _NavigatorObserver extends NavigatorObserver {
@override
void didPop(Route route, Route? previousRoute) {
_depth--;
print("DEPTH : $_depth");
super.didPop(route, previousRoute);
}
@override
void didPush(Route route, Route? previousRoute) {
_depth++;
print("DEPTH : $_depth");
super.didPush(route, previousRoute);
}
}