Getx: How to pass data from StatelessWidget to GetxController?

Created on 20 Feb 2021  ยท  8Comments  ยท  Source: jonataslaw/getx

I have declare this on class that extends GetxController:

  var tipo = Get.arguments;
  var idPaciente = Get.arguments;
  var beneficiario = Get.arguments;
  var ciudadesList = Get.arguments;
  var nacionalidadesList = Get.arguments;

Where this is the type on each var:

  String tipo;
  int idPaciente;
  Beneficiario beneficiario;
  var ciudadesList = <Ciudades>[].obs;
  var nacionalidadesList = <Nacionalidades>[].obs;

So in the StatelessWidget i call this class GetxController like this:

Get.to(() => DetalleBeneficiario(), 
                  arguments: {'editar', 
                  controller.beneficiariosList[i], 
                  controller.ciudadesList[i], 
                  controller.nacionalidadesList[i], 
                  controller.idPaciente});

But i have this error:

โ•โ•โ•โ•โ•โ•โ•โ• Exception caught by widgets library โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
The following NoSuchMethodError was thrown building DetalleBeneficiario(dirty):
Class 'String' has no instance getter 'nombre'.
Receiver: "editar"
Tried calling: nombre

I printed this before Get.to(...) and is work just fine:

print(controller.beneficiariosList[i].apellido);
print(controller.ciudadesList[i].nombre);
print(controller.nacionalidadesList[i].descripcion);
print(controller.idPaciente);

Can help me pls?

Improper use of GetX Without a valid reproduction code

Most helpful comment

Try this:

Get.to(() => DetalleBeneficiario(), arguments: {
                  'tipo': 'editar', 
                  'beneficiarios': controller.beneficiariosList[i], 
                  'ciudades': controller.ciudadesList[i], 
                  'nacionalidades': controller.nacionalidadesList[i], 
                  'idPaciente': controller.idPaciente
});
final arguments = Get.Arguments;
print(arguments['action']);
print(arguments['beneficiarios'][i].apellido);
print(arguments['ciudades'][i].nombre);
...

All 8 comments

Can you please post some reproduce code? not just partially?

Hi, sorry!
The main questions now is how to access this parameters:

String tipo;
  int idPaciente;
  Beneficiario beneficiario;
  var ciudadesList = <Ciudades>[].obs;
  var nacionalidadesList = <Nacionalidades>[].obs;

By now can only access to String type with print(Get.arguments[0]); but not custom type and List.

Try this:

Get.to(() => DetalleBeneficiario(), arguments: {
                  'tipo': 'editar', 
                  'beneficiarios': controller.beneficiariosList[i], 
                  'ciudades': controller.ciudadesList[i], 
                  'nacionalidades': controller.nacionalidadesList[i], 
                  'idPaciente': controller.idPaciente
});
final arguments = Get.Arguments;
print(arguments['action']);
print(arguments['beneficiarios'][i].apellido);
print(arguments['ciudades'][i].nombre);
...

Hey, @eduardoflorence thanks!

I have this:

      Map<String, dynamic> arguments = Get.arguments;
      this.tipo = arguments['tipo'];
      this.idPaciente = arguments['idPaciente'];
      this.beneficiario = arguments['beneficiario'];
      this.ciudadesList = arguments['ciudadesList'];
      this.nacionalidadesList = arguments['nacionalidadesList'];

But it fail on this.ciudadesList = arguments['ciudadesList'] output:

type 'Ciudades' is not a subtype of type 'RxList<Ciudades>'

Clarity i am noob in flutter and Getx. But when is RxString i use ".value" but what about for RxList?

this.ciudadesList.assignAll(...)

On Tue, 23 Feb 2021, 04:46 Alejandro, notifications@github.com wrote:

Hey, @eduardoflorence https://github.com/eduardoflorence thanks!

I have this:

  Map<String, dynamic> arguments = Get.arguments;
  this.tipo = arguments['tipo'];
  this.idPaciente = arguments['idPaciente'];
  this.beneficiario = arguments['beneficiario'];
  this.ciudadesList = arguments['ciudadesList'];
  this.nacionalidadesList.reactive.value = arguments['nacionalidadesList'];

But it fail on this.ciudadesList = arguments['ciudadesList'] output:

type 'Ciudades' is not a subtype of type 'RxList'

Clarity i am noob in flutter and Getx. But when is RxString i use ".value"
but what about for RxList?

โ€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/jonataslaw/getx/issues/1095#issuecomment-783695843,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAOVMXCEYT363TAKH6A75ADTALGCFANCNFSM4X56ANSQ
.

hi @ghprod thank for the response, but i try this:

      this.ciudadesList.addAll(arguments['ciudadesList']);
      this.ciudadesList.add(arguments['ciudadesList']);

With not success, also i declare variable ciudadesList like this:

List<Ciudades> ciudadesList = <Ciudades>[].obs;

I recibe this error:

type 'Ciudades' is not a subtype of type 'Iterable<Ciudades>'

I don't know this is relate to Getx anymore, but you can help me one last time at least?

Can you make some reproduce code? It's so hard to help with just a piece of code.

Sorry, is my fault, i don't pass list type in arguments, instead this:

Get.to(() => DetalleBeneficiario(), arguments: {
                  'tipo': 'editar', 
                  'beneficiarios': controller.beneficiariosList[i], 
                  'ciudades': controller.ciudadesList[i], 
                  'nacionalidades': controller.nacionalidadesList[i], 
                  'idPaciente': controller.idPaciente
});

now pass like this:

Get.to(() => DetalleBeneficiario(), arguments: {
                  'tipo': 'editar', 
                  'beneficiarios': controller.beneficiariosList[i], 
                  'ciudades': controller.ciudadesList, 
                  'nacionalidades': controller.nacionalidadesList, 
                  'idPaciente': controller.idPaciente
});

Thanks to all for help me...

Was this page helpful?
0 / 5 - 0 ratings