我正在尝试使用NavigatorMiddleWare
下面是我的主要.dart代码:
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((value) => runApp(const MyApp()));
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: Strings.appTitle,
theme: AppTheme().light(),
initialRoute: NavigationManager.returnNavigationRoute(),
onGenerateRoute: RouteGenerator.generateRoute,
navigatorObservers: [RouteManager.routeObserver, RouteManager.middleware],
);
}
}
我的路由管理器类:
class RouteManager {
static final RouteObserver<PageRoute> routeObserver =
RouteObserver<PageRoute>();
static final NavigatorMiddleware<PageRoute> middleware =
NavigatorMiddleware<PageRoute>(
onPush: (route, previousRoute) {
log('we have push event');
},
);
}
在我身边似乎一切都很好。tutorial
添加了NavigatorMiddleWare代码:NavigationMiddleWare
1条答案
按热度按时间monwx1rj1#
将您的中间件代码替换为以下代码:
希望有帮助