【问题标题】:how to make getx flutter to move to the next middleware如何使 getx 颤振以移动到下一个中​​间件
【发布时间】:2021-09-21 19:28:25
【问题描述】:

您好,我正在使用 getx 颤振中间件。关于将中间件列表提供给页面。如何确认一个中间件的结束,以便 getx 可以移动到下一个。

例如:首页有两个中间件 1. 第一个中页 2. 第二个中页 在调用主页时,应用程序将重定向到第一个中页。现在在第一个中页完成我的任务后,我如何要求应用重定向到第二个中页。

【问题讨论】:

    标签: flutter-getx


    【解决方案1】:

    main.dart

    routingCallback:
          Get.find<AppService>(tag: Const.appService).routRecord,
    

    app_service.dart

    String rout = "";
    
    void routRecord(Routing? r) {
      if (r != null) {
        if (r.current == Routes.HOME) {
          rout = Routes.HOME;
        } else if (r.isBack ?? false) {
          final pos = rout.lastIndexOf('/');
          rout = (pos != -1) ? rout.substring(0, pos) : rout;
        } else if (r.current != "") {
          rout = rout + r.current;
        }
      }
    }
    

    我有一个在 rout 中打开的页面路径。 即:家庭/用户/个人资料 我可以很容易地知道我在哪里,并且可以很容易地转到另一个页面。

    即:app_service.dart

      void _appListener() async {
        ReceiveSharingIntent.getTextStream().listen((String value) {
          _openPlayer(value);
        }, onError: (err) {
          Message.show("Error", "Something went wrong");
        });
     
        await ReceiveSharingIntent.getInitialText().then((value) {
          if (value != null) _openPlayer(value);
        });
      }
    
      _openPlayer(String url) async {
        final id = YoutubePlayerController.convertUrlToId(url);
        if (id != null) {
          final _routStack = rout.split('/');
          final playerIndex = _routStack
              .indexWhere((element) => element == Routes.PLAYER.substring(1));
    
          if (playerIndex == -1) {
            Get.toNamed(Routes.PLAYER, arguments: [
              id,
              (await FetchDetails.getDetail(id))?["title"] ?? "",
            ]);
          } else {
            final backCount = _routStack.length - playerIndex;
            for (int i = 0; i < backCount; i++) {
              Get.back();
            }
            Get.toNamed(Routes.PLAYER, arguments: [
              id,
              (await FetchDetails.getDetail(id))?["title"] ?? "",
            ]);
          }
        } else {
          Message.show("Error", "invalid url");
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2022-01-05
      • 2021-10-05
      • 2021-11-29
      • 2021-03-02
      • 2021-06-08
      • 2021-11-19
      • 2021-09-12
      • 2021-12-07
      • 2021-10-06
      相关资源
      最近更新 更多