简体   繁体   English

错误:根据闭包上下文的要求,返回类型“NetworkImage”不是“Widget”

[英]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 命名事物的方式有点令人困惑,但NetworkImageImageProvider ,而不是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.

相关问题 返回类型“小部件?” 不是闭包上下文所要求的“小部件” - The return type 'Widget?' isn't a 'Widget', as required by the closure's context 根据闭包上下文的要求,返回类型“Object”不是“Widget” - The return type 'Object' isn't a 'Widget', as required by the closure's context 根据闭包上下文的要求,返回类型“Person”不是“Widget” - The return type 'Person' isn't a 'Widget', as required by the closure's context 返回类型“_MainPage”不是闭包上下文所要求的“Widget” - The return type '_MainPage' isn't a 'Widget', as required by the closure's context 错误:返回类型“CategoryState”不是“Widget”,这是闭包上下文所要求的 - error: The return type 'CategoryState' isn't a 'Widget', as required by the closure's context 错误消息:根据闭包上下文的要求,返回类型“void”不是“Widget” - Error Message: The return type 'void' isn't a 'Widget', as required by the closure's context 返回类型 &#39;Set<Text> &#39; 不是闭包上下文所要求的 &#39;Widget&#39; - The return type 'Set<Text>' isn't a 'Widget', as required by the closure's context 返回类型 &#39;Future<dynamic> &#39; 不是闭包上下文所要求的 &#39;Widget&#39; - The return type 'Future<dynamic>' isn't a 'Widget', as required by the closure's context 返回类型 'Future<img> ' 不是闭包上下文所要求的 'Widget' - The return type 'Future<Image>' isn't a 'Widget', as required by the closure's context 返回类型“SliverAppBar?” 不是&#39;列表<Widget> &#39;,根据闭包上下文的要求 - The return type 'SliverAppBar?' isn't a 'List<Widget>', as required by the closure's context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM