Flutter Getx 中间件配置
Flutter Getx 对应视频教程访问:https://www.itying.com/goods-1176.html
Flutter Getx 中间件配置更多详情参考:https://github.com/jonataslaw/getx/blob/master/README.zh-cn.md#redirect
一、Flutter Getx 中间件配置第一步新建shopMiddleware.dart
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
class ShopMiddleWare extends GetMiddleware {
@override
// 优先级越低越先执行
int? get priority => -1;
@override
RouteSettings redirect(String ? route){
return const RouteSettings(name: '/login');
}
}
二、Flutter Getx 中间件配置 GetPage配置路由
return GetMaterialApp(
...
initialRoute: "/",
defaultTransition: Transition.rightToLeftWithFade,
getPages: [
GetPage(name: "/", page: () => const Tabs()),
...
GetPage(
name: "/shop",
page: () => const ShopPage(),
middlewares: [ShopMiddleWare()]),
],
);