getx icon indicating copy to clipboard operation
getx copied to clipboard

Get.toNamed

Open vptcnt opened this issue 3 years ago • 3 comments

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,
              );

vptcnt avatar May 16 '22 16:05 vptcnt

if you want to push a new ArticlePage you should close now. Get.offNamed("page",preventDuplicates: false);

Qingx avatar May 19 '22 10:05 Qingx

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

liasica avatar May 25 '22 07:05 liasica

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

jjvillavicencio avatar Jul 29 '22 15:07 jjvillavicencio

i meet same question

kulame avatar Aug 30 '23 02:08 kulame

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

heralight avatar Sep 08 '23 09:09 heralight