【问题标题】:flutter: type 'Future<dynamic>' is not a subtype of type 'Widget?' error颤振:类型“Future<dynamic>”不是“Widget”类型的子类型?错误
【发布时间】:2021-10-21 08:02:20
【问题描述】:

我得到“类型‘未来’不是‘小部件’类型的子类型? “在我的 ios 模拟器中。我该如何摆脱这个?请帮忙。
这是我的代码。

 Widget build(BuildContext context) {
return Scaffold( ...

 body: cropImage(PickedFile)
 
);



cropImage(pickedFile) async {
File? croppedImage = await ImageCropper.cropImage(
  sourcePath: pickedFile,
  maxWidth: 1080,
  maxHeight: 1080,
);
if (croppedImage != null) {
  var image = croppedImage;
  setState(() {});

【问题讨论】:

    标签: ios flutter widget future subtype


    【解决方案1】:

    你必须在body参数中给出Widget的子类型,因为cropimage()类型是Future,而不是Widget

    这样

    Widget build(BuildContext context) {
    return Scaffold( ...
    
     body: Text('Hello')
     
    );
    

     Widget build(BuildContext context) {
    return Scaffold( ...
    
     body: Center(child:Text('Hello'))
     
    );
    

    【讨论】:

      猜你喜欢
      • 2020-01-01
      • 1970-01-01
      • 2020-09-11
      • 2021-02-17
      • 2023-03-27
      • 1970-01-01
      • 2021-10-18
      • 2019-08-18
      相关资源
      最近更新 更多