0

Hi I'm using getx flutter middleware . on giving a list of middlewares to a page. How to acknowledge the end of one middleware so getx can move to the next one.

for example: homepage has two middlewares 1. first midpage 2. second midpage on calling home page the app will redirect to first midpage. now on having finished my task in first midpage, how do i ask the app to redirect to the second midpage.

harish balaji
  • 33
  • 1
  • 6

1 Answers1

0

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;
    }
  }
}

I have a path of pages that I have open in rout. ie: home/user/profile I can easily know where I am, and can easily go to another page.

ie: 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");
    }
  }
Alok Kumar
  • 397
  • 1
  • 4
  • 15