如何修复错误&quot“参数类型”对象?'可以分配给参数类型吗?
我正在尝试从Firebase存储中检索图像。我正在遵循YouTube教程,错误是在 snapshot.data 上说参数类型“对象?”无法分配到参数类型“小部件?” 。
请帮助我解决此错误。太感谢了。
final String image1 = "images/image0.png";
final String image2 = "images/image0.png";
String image = image1;
class LoadFirebaseStorageImage extends StatefulWidget {
const LoadFirebaseStorageImage({Key? key}) : super(key: key); ```
Container(
height: double.infinity,
margin: const EdgeInsets.only(left: 30, right: 30, top: 10),
child: ClipRRect(
borderRadius: BorderRadius.circular(30),
child: FutureBuilder(
future: _getImage(context, image),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done)
return Container(
height: MediaQuery.of(context).size.height / 1.25,
width: MediaQuery.of(context).size.width / 1.25,
child: snapshot.data);
if (snapshot.connectionState == ConnectionState.waiting)
return Container(
height: MediaQuery.of(context).size.height / 1.25,
width: MediaQuery.of(context).size.width / 1.25,
child: CircularProgressIndicator());
return Container();
},
),
),
),
],
),
),
loadButton(context),
],
),
);
} }``````
I am trying to retrieve an image from firebase storage. I was following a YouTube tutorial and the error was on the snapshot.data saying The argument type 'Object?' can't be assigned to the parameter type 'Widget?'.
Please help me to fix this error. Thank you so much.
final String image1 = "images/image0.png";
final String image2 = "images/image0.png";
String image = image1;
class LoadFirebaseStorageImage extends StatefulWidget {
const LoadFirebaseStorageImage({Key? key}) : super(key: key); ```
Container(
height: double.infinity,
margin: const EdgeInsets.only(left: 30, right: 30, top: 10),
child: ClipRRect(
borderRadius: BorderRadius.circular(30),
child: FutureBuilder(
future: _getImage(context, image),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done)
return Container(
height: MediaQuery.of(context).size.height / 1.25,
width: MediaQuery.of(context).size.width / 1.25,
child: snapshot.data);
if (snapshot.connectionState == ConnectionState.waiting)
return Container(
height: MediaQuery.of(context).size.height / 1.25,
width: MediaQuery.of(context).size.width / 1.25,
child: CircularProgressIndicator());
return Container();
},
),
),
),
],
),
),
loadButton(context),
],
),
);
}
}```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在FutureBuilder上指示快照的类型,例如
假设
_getImage
返回widget
you need to indicate the type of the snapshot at the FutureBuilder, like
This is assuming that
_getImage
returns aWidget
您会遇到此错误,因为您已将
snapshot.data
直接解析到小部件。您无法将数据直接传递给小部件。首先,请检查您在
snapshot.data
printing it上获得什么。如果要获取图像的网络URL,则可以像以下内容一样使用它。
您将始终在
snapshot.data
中获取一些数据,而不是widget
。只需检查您获得的
打印
功能即可。You are getting this error because you have parsed
snapshot.data
directly to the widget. You can not pass the data directly to the widget.first, check what are you getting on
snapshot.data
byprinting
it.if you are getting the network URL of the image then you can use it like below.
you will always get some data not
widget
insnapshot.data
.just check what are you getting
print
function.