flutter imagepicker甚至不显示File imagefile的值

问题描述

嗨,所以我设法通过setstate将数据添加到我的图像文件中,但它似乎仍然没有更新我的Image.file()或不显示任何内容

重要提示,当我没有单独进行编码并且在 MAIN 代码中进行了所有编码时,一切似乎都很好。但是,如果我分开使用,则它不起作用,并且即使打印似乎显示了某些内容

这里是我的代码

这里是我的主要代码

class SecondPage extends StatefulWidget {
  @override
  _SecondPageState createState() => _SecondPageState();
}

class _SecondPageState extends State<SecondPage> {
  Future<File> callBackMethod(File myImage) async {
    final PickedFile pickedFile =
        await ImagePicker().getimage(source: ImageSource.gallery);
    setState(() {
      myImage = File(pickedFile.path);
    });
    return myImage;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          body:
              SecondPageUI(this.context,this.callBackMethod).mySecondPageUI()),);
  }
}

这是SecondPageUi()

class SecondPageUI {
  final BuildContext context;
  File imageFile;
  Function myCallBack;

  SecondPageUI(this.context,this.myCallBack);

  Widget mySecondPageUI() {
    final Size mediaSize = MediaQuery.of(context).size;
    return Stack(
      children: [
        GestureDetector(
          onTap: () {
            ongallery();
          },child: Center(
            child: Container(
              child: myImageGetter(),),)
      ],);
  }

  Widget myImageGetter() {
    if (imageFile != null) {
      print("image file path 1111 : "+imageFile.path);
      return Image.file(
        imageFile,width: 200,height: 200,fit: BoxFit.fill,filterQuality: FilterQuality.high,);
    } else {
      return Icon(Icons.add);
    }
  }

  Future<void> ongallery() async {
    imageFile = await myCallBack(imageFile);
    print("image file path: "+imageFile.path);
  }
}

以下是输出: 它会显示(图像文件路径:/data/user/0/com.kislap.firebasetestarea/cache/image_picker5841434212368857862.jpg)

Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 2,437ms.
W/DynamiteModule(16202): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(16202): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(16202): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
I/irebasetestare(16202): Waiting for a blocking GC ProfileSaver
W/ConnectivityManager.CallbackHandler(16202): callback not found for CALLBACK_AVAILABLE message
I/irebasetestare(16202): WaitForGcToComplete blocked ProfileSaver on HeapTrim for 25.541ms
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/EGL_emulation(16202): eglMakeCurrent: 0xe34028a0: ver 3 0 (tinfo 0xe3400780)
I/Flutter (16202): image file path: /data/user/0/com.kislap.firebasetestarea/cache/image_picker5841434212368857862.jpg
E/Surface (16202): getSlotFromBufferLocked: unkNown buffer: 0x700073
W/libEGL  (16202): EGLNativeWindowType 0xe00fe808 disconnect Failed
D/EGL_emulation(16202): eglMakeCurrent: 0xebf493a0: ver 3 0 (tinfo 0xcbfc5070)
D/EGL_emulation(16202): eglMakeCurrent: 0xe34028a0: ver 3 0 (tinfo 0xe3400780)
D/EGL_emulation(16202): eglMakeCurrent: 0xebf493a0: ver 3 0 (tinfo 0xcbfc5070)
D/eglCodecCommon(16202): setVertexArrayObject: set vao to 0 (0) 0 0
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 
D/skia    (16202): Shader compilation error
D/skia    (16202): ------------------------
D/skia    (16202): Errors:
D/skia    (16202): 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)