Get.toNamed
Hello, I use Getx to get articles from Wordpress. I display the list of articles correctly via a ListPage calling a controller ListController. I can click on an item in the list and display the content of the article via an ArticlePage using a controller ArticleController. Inside the article, there are links to other internal articles. And I would like to push the same page to load the new article. To do something like this: ListPage > ArticlePage (article A) > ArticlePage (article B)> ArticlePage (article C)
I succeed to achieve this. But when I pop to go back, the last article is displayed.
ListPage > ArticlePage (article C !!!! ☹️) > ArticlePage (article C !!!! ☹️ )> ArticlePage (article C)
Any ideas ?
I used :
// From ListPage to first ArticlePage
await Get.toNamed(
'/articlePage',
arguments: url,
);
and
class ArticlePage extends StatefulWidget {
final String slug;
ArticleBySlugScreen({Key? key,}) : slug = Get.arguments, super(key: key);
@override
State< ArticlePage > createState() => _ ArticlePage State();
}
class _ ArticlePage State extends State< ArticlePage > {
ArticleController controller = Get.find<ArticleController>();
@override
Widget build(BuildContext context) {
Future.delayed(Duration.zero, () async => await controller.fetch(post));
return GetBuilder<ArticleController>(
builder: (controller) {
if (controller.status.isLoading) {
return LoadingScreen();
}
return DisplayArticle(controller.state!);
}
);
}
}
DisplayArticle can detect links and calls :
// From DisplayArticle to push an new ArticlePage from another ArticlePage
await Get.toNamed(
'/articlePage',
arguments: url,
preventDuplicates: false,
);
if you want to push a new ArticlePage you should close now.
Get.offNamed("page",preventDuplicates: false);
if you want to push a new ArticlePage you should close now.
Get.offNamed("page",preventDuplicates: false);
I tried offNamed, but I can't Get.back
Hello, I use Getx to get articles from Wordpress. I display the list of articles correctly via a ListPage calling a controller ListController. I can click on an item in the list and display the content of the article via an ArticlePage using a controller ArticleController. Inside the article, there are links to other internal articles. And I would like to push the same page to load the new article. To do something like this: ListPage > ArticlePage (article A) > ArticlePage (article B)> ArticlePage (article C)
I succeed to achieve this. But when I pop to go back, the last article is displayed.
ListPage > ArticlePage (article C !!!! ☹️) > ArticlePage (article C !!!! ☹️ )> ArticlePage (article C)
Any ideas ?
I used :
// From ListPage to first ArticlePage await Get.toNamed( '/articlePage', arguments: url, );and
class ArticlePage extends StatefulWidget { final String slug; ArticleBySlugScreen({Key? key,}) : slug = Get.arguments, super(key: key); @override State< ArticlePage > createState() => _ ArticlePage State(); } class _ ArticlePage State extends State< ArticlePage > { ArticleController controller = Get.find<ArticleController>(); @override Widget build(BuildContext context) { Future.delayed(Duration.zero, () async => await controller.fetch(post)); return GetBuilder<ArticleController>( builder: (controller) { if (controller.status.isLoading) { return LoadingScreen(); } return DisplayArticle(controller.state!); } ); } }DisplayArticle can detect links and calls :
// From DisplayArticle to push an new ArticlePage from another ArticlePage await Get.toNamed( '/articlePage', arguments: url, preventDuplicates: false, );
I have the same problem, any solution?, I can not call the same page for the second time with different arguments
i meet same question
To refresh your details on new arguments, you need to listen to them. To do that, You can add final parameter = ModalRoute.of(context)!.settings; in you build function or move your Get.arguments inside the binding method (see getx examples) .
Best regards,
Alexandre