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