'Passing model object as an argument with Flutter GetX

I need a model object on two screens.

I have 2 questions:

  1. Is passing a model object (from one screen to another) required if we are using GetX?

  2. If yes, how do we do it?

     return GestureDetector(
      onTap: () {
        Get.toNamed('/field_details/', arguments: fieldModel);
      },
    

In main.dart:

GetPage(
  name: '/field_details',
  page: () => FieldDetailsScreen(//how do I get the model to be passed here, it won't be available in the main function),
),


Solution 1:[1]

You can use Get.arguments for that.

GetPage(
   name: '/field_details',
   page: () => FieldDetailsScreen(Get.arguments),
),

You will get your model here but you need to convert arguments into model by using your model's fromjosn method.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 InFicial Infotech