小编lax*_*ore的帖子

如何在 GetxController 中将 Get.arguments 处理为 null

我有以下 GetX 控制器将参数传递到 Flutter 中的页面:

更新

class HomeController extends GetxController {

  File image;
  String ocr_text;

  onInit(){
    super.onInit();

    image = Get.arguments['image'];
    ocr_text = Get.arguments['ocr_text'];

    update();
  }

}
Run Code Online (Sandbox Code Playgroud)

捆绑:

class HomeBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut<HomeController>(() => HomeController());
  }
}
Run Code Online (Sandbox Code Playgroud)

我想从 Ocr_details 页面传递图像:

FlatButton(
            color: Colors.blue,
            child: Icon(Icons.save_outlined),
              onPressed: () {
                Get.toNamed(
                  AppRoutes.HOME,
                  arguments: {'image': controller.image, 'ocr_text': controller.text},
                );
              }
          ),

Run Code Online (Sandbox Code Playgroud)

到主页:

更新:

Container(
                padding: EdgeInsets.all(32),
                child:  GetBuilder<HomeController>(
                  builder: (_) {
                    return _.image != null
                        ? Image.file(_.image)
                        : …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-getx

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

dart ×1

flutter ×1

flutter-getx ×1