【问题标题】:Flutter: type _file is not a subtype of type widgetFlutter:type _file 不是类型小部件的子类型
【发布时间】:2021-10-23 01:25:01
【问题描述】:

我得到 type _file is not a subtype of type widget 错误,这是我的代码。 我正在尝试将在cropImage 中裁剪的裁剪图像移动到editImage 小部件。

  _getFromGallery() async {
XFile? pickedFile = await ImagePicker().pickImage(
  source: ImageSource.gallery,
  maxWidth: 1800,
  maxHeight: 1800,
);
_cropImage(pickedFile!.path);

}

_cropImage(pickedFile) async {
File? croppedImage = await ImageCropper.cropImage(
  sourcePath: pickedFile,
  maxWidth: 1080,
  maxHeight: 1080,
);
if (croppedImage != null) {
  image = croppedImage;
  Navigator.of(context).push(
      MaterialPageRoute(builder: (context) => editImage(croppedImage)));
}

}

  Widget editImage(croppedImage) {
final Future<String> _croppedImage = Future<String>.delayed(
  const Duration(seconds: 2),
  () => 'Data Loaded',
);
return FutureBuilder<String>(
    future: _croppedImage,
    builder: (BuildContext context, snapshot) {
      if (snapshot.hasData) {}
      return Center(
        child: Scaffold(
          appBar: AppBar(
            title: Text('Edit Image'),
          ),
          body: Container(child: image = croppedImage),
        ),
      );
    });

} }

我可以获得正确的代码示例吗?我被困在这几个星期了。请帮忙。

【问题讨论】:

    标签: image flutter file widget


    【解决方案1】:

    flutter 根树只能显示从小部件类继承的类。将您的代码更改为:

       Widget editImage(croppedImage) {
    final Future<String> _croppedImage = Future<String>.delayed(
      const Duration(seconds: 2),
      () => 'Data Loaded',
    );
    return FutureBuilder<String>(
        future: _croppedImage,
        builder: (BuildContext context, snapshot) {
          if (snapshot.hasData) {}
          return Center(
            child: Scaffold(
              appBar: AppBar(
                title: Text('Edit Image'),
              ),
              body:croppedImage !=null? Container(child: Image.file(croppedImage!)):null,
            ),
          );
        });
    } }
    

    【讨论】:

    • walla gever gever!
    猜你喜欢
    • 2019-02-15
    • 1970-01-01
    • 2020-01-27
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多