[英]error: The return type 'NetworkImage' isn't a 'Widget', as required by the closure's context
import 'package:carousel_pro/carousel_pro.dart';
import '../models/post_model.dart';
Carousel(
animationDuration: null,
images: [
ListView.builder(
itemCount: posts[index].MediaImage.length,
physics: ScrollPhysics(),
itemBuilder: (context, index) {
return NetworkImage(posts[index].MediaImage[index].image);
}, ) ],) ,
I am trying to show multiple images from Network.我正在尝试显示来自网络的多个图像。 Does anybody know why i am getting this error?
有人知道我为什么会收到这个错误吗?
Return the following in your itemBuilder在您的 itemBuilder 中返回以下内容
return Image.network(posts[index].MediaImage[index].image);
You cant use a ListView.builder inside of carousel, why would you even use that??您不能在轮播中使用 ListView.builder,为什么还要使用它?
Carousel expect NetworkImage only as a string of url and placing any other widget inside of that will land you to this error. Carousel 期望 NetworkImage 仅作为 url 的字符串,并且在其中放置任何其他小部件将使您陷入此错误。
0 0
import 'package:carousel_pro/carousel_pro.dart';
import '../models/post_model.dart';
Carousel(
animationDuration: null,
images: [NetworkImage(posts[i].MediaImage[i].image.toString(),],) ,
This is the correct way, .toString(), is often required as NetworkImage expects a String.这是正确的方法,通常需要.toString(),因为 NetworkImage 需要一个字符串。
If you have multiple images use:如果您有多个图像,请使用:
for(int i =0;i<="please specify your length here", i++);
I have added i
in place of index.我添加了
i
来代替索引。
Carousel never takes anyother Widget than AssetImage or NetworkImage directly. Carousel 从不直接使用除 AssetImage 或 NetworkImage 之外的任何其他 Widget。
It's a bit confusing from the way that Flutter names things, but NetworkImage
is an ImageProvider
, not a Widget
(which actually shows the image). Flutter 命名事物的方式有点令人困惑,但
NetworkImage
是ImageProvider
,而不是Widget
(实际上显示图像)。 The widget you want is Image
, which can be constructed from an ImageProvider
, or can be constructed from an URL directly via its Image.network
constructor .您想要的小部件是
Image
,它可以从ImageProvider
构造,也可以直接通过其Image.network
构造函数从 URL 构造。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.