I have following GetX controller to pass parameters to page in Flutter:
UPDATED
class HomeController extends GetxController {
File image;
String ocr_text;
onInit(){
super.onInit();
image = Get.arguments['image'];
ocr_text = Get.arguments['ocr_text'];
update();
}
}
Binding:
class HomeBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<HomeController>(() => HomeController());
}
}
I want to pass image from Ocr_details page:
FlatButton(
color: Colors.blue,
child: Icon(Icons.save_outlined),
onPressed: () {
Get.toNamed(
AppRoutes.HOME,
arguments: {'image': controller.image, 'ocr_text': controller.text},
);
}
),
to home page:
UPDATED:
Container(
padding: EdgeInsets.all(32),
child: GetBuilder<HomeController>(
builder: (_) {
return _.image != null
? Image.file(_.image)
: Container();
},
),
),
GetPages
class AppPages {
static var list = [
GetPage(
name: AppRoutes.HOME,
page: () => HomePage(),
binding: HomeBinding(),
),
GetPage(
name: AppRoutes.PICK_IMAGE,
page: () => PickImagePage(),
binding: PickImageBinding(),
),
GetPage(
name: AppRoutes.OCR_DETAILS,
page: () => OCRDetailsPage(),
binding: OCRDetailsBinding(),
)
];
}
Routes
class AppRoutes {
static const String HOME = '/';
static const String PICK_IMAGE = '/pick_image';
static const String OCR_DETAILS = '/ocr_details';
}
But I'm getting following error: The following NoSuchMethodError was thrown building HomePage(dirty): The method '[]' was called on null. Receiver: null Tried calling:
I dont know if there is a way to check if argument is null and continue with rendering a widget?