Search code examples
flutterdartflutter-getx

Passing and Receiving Arguments Using Getx


I'm trying to pass arguments when moving from one window to another using Getx routing. During the transition, I pass one Uint8List:

Uint8List jpeg = Uint8List.fromList(img.encodeJpg(image)); Get.toNamed(RoutesClass.getPreviewRoute(), arguments: jpeg);

In the receiving class, I do the following:

Uint8List jpeg = Get.arguments;

to display the resulting image I use the following:

decoration: BoxDecoration(image: DecorationImage( fit: BoxFit.cover, image: MemoryImage(controller.jpeg),)),)

But the jpeg in the receiving class is always empty. What did I miss and why is my jpeg empty? When

When trying to display a jpeg from the arguments, I observe the following:

screenshot

But if I try to display the jpeg on the first screen, then I see the picture.


Solution

  • Initialize the jpeg in the onInit method of the receiving class's controller:

      @override
      void onInit() async {
        super.onInit();
        jpeg = Get.arguments;
      }