0

I have this route

Get.toNamed('/community/discussion/${controller.community.topicId}}');

While navigating to the view, I want to pass the route parameter topicId to the view's controller so that it uses as document ID and load the content which will be stream to the view.

How can I send this parameter to the controller before the view's content is streamed?

Joseph Attia
  • 306
  • 3
  • 17
Clid3
  • 9
  • 3

2 Answers2

1

I guess you're not using Get.toNamed the way it is supposed to.

Function toNamed takes a dynamic parameter arguments that you can use for your purpose.

In your source screen:

Get.toNamed<void>("/community/discussion/",
    arguments: {"topicId": controller.community.topicId});

In your destination screen:

var topicId = Get.parameters['topicId'];

Then you can easily set the topic id into your controller:

controller.topicId = topicId;

class YourController extends GetxController {
   int? topicId;
}
Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64
0

If what you're trying to pass already lives in a GetX class, which it appears that it does, then you don't need to pass it at all. Anything that lives in a GetX class is already accessible from anywhere with Get.find...

Just access it on the next page with

Get.find<WhateverThisClassIsCalled>().community.topicId
Loren.A
  • 4,872
  • 1
  • 10
  • 17
  • Actually topicId is just an index obtained when iterating a stream. this index represent a documentId from firestore which i want to pass it to the controller of the next page so as to load the subcollection under this topicId. – Clid3 Apr 28 '21 at 10:22