Flutter Getx 中间件配置

发布于 1 年前 作者 phonegap100 418 次浏览 最后一次编辑是 1 年前 来自 分享

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()]),
      ],      
    );
回到顶部