Dart 如何在旋转木马视图中添加fadeinImage

Dart 如何在旋转木马视图中添加fadeinImage,dart,flutter,carousel,flutter-layout,Dart,Flutter,Carousel,Flutter Layout,我有以下代码,它在旋转木马中显示网络图像。当我启动我的应用程序时,我在旋转木马中看到一个空白的白色屏幕。我想显示一个占位符图像。我试图将占位符图像放在if子句下,但if子句仅在我导航到另一个屏幕并返回到carousel屏幕时才显示占位符。我希望在启动应用程序时显示占位符。我怎样才能做到这一点 return Container( child: FutureBuilder( future: getCarouselWidget(), builder: (context, A

我有以下代码,它在旋转木马中显示网络图像。当我启动我的应用程序时,我在旋转木马中看到一个空白的白色屏幕。我想显示一个占位符图像。我试图将占位符图像放在if子句下,但if子句仅在我导航到另一个屏幕并返回到carousel屏幕时才显示占位符。我希望在启动应用程序时显示占位符。我怎样才能做到这一点

return Container(
  child: FutureBuilder(
      future: getCarouselWidget(),
      builder: (context, AsyncSnapshot snapshot) {
        List<NetworkImage> list = new List<NetworkImage>();
        if (snapshot.connectionState == ConnectionState.waiting || snapshot.connectionState == ConnectionState.active
        ) {
          debugPrint("connection state is " + snapshot.connectionState.toString() );
          return new FadeInImage(
            height: 200.0, // Change it to your need
            width: 300.0, // Change it to your need
            fit: BoxFit.cover,
            placeholder: new AssetImage("assets/placeholder.jpg"),
            image: new AssetImage("assets/placeholder.jpg"),
          );
        } else if(snapshot.connectionState == ConnectionState.done) {
          debugPrint("connection state is inside else" + snapshot.connectionState.toString() );
          if (snapshot.hasError) {
            return new Text("fetch error");
          } else {
            for (int i = 0; i < snapshot.data.length; i++) {
              //debugPrint("Index is " + idx.toString());
              list.add(NetworkImage(snapshot.data[i].data["image"]));
              //idx++;
            }
            return new Container(
                height: 250.0,
                child: InkWell(
                    child: new Carousel(
                      boxFit: BoxFit.cover,
                      images: list,
                      onImageTap: (imageIndex) {
                        Navigator.of(context).push(
                          new MaterialPageRoute(
                            builder: (context) => new CustomClass(
                                name:
                                    snapshot.data[imageIndex].data["title"],
                                pic: snapshot
                                    .data[imageIndex].data["image"]),
                          ),
                        );
                      },
                      autoplay: false,
                      dotSize: 4.0,
                      indicatorBgPadding: 4.0,
                      animationCurve: Curves.fastOutSlowIn,
                      animationDuration: Duration(milliseconds: 1000),
                    )));
          }
        }
      }),
);
返回容器(
孩子:未来建设者(
future:getCarouselWidget(),
生成器:(上下文,异步快照){
列表=新列表();
如果(snapshot.connectionState==connectionState.waiting | | snapshot.connectionState==connectionState.active
) {
debugPrint(“连接状态为”+snapshot.connectionState.toString());
返回新的FadeInImage(
高度:200.0,//根据需要更改
宽度:300.0,//根据需要更改
适合:BoxFit.cover,
占位符:新资产图像(“assets/placeholder.jpg”),
图像:新资产图像(“assets/placeholder.jpg”),
);
}else if(snapshot.connectionState==connectionState.done){
debugPrint(“连接状态在else内部”+snapshot.connectionState.toString());
if(snapshot.hasError){
返回新文本(“获取错误”);
}否则{
对于(int i=0;i新自定义类(
姓名:
snapshot.data[imageIndex].data[“title”],
图片:快照
.data[imageIndex].data[“image”]),
),
);
},
自动播放:错误,
dotSize:4.0,
指示符号RBGPAdd:4.0,
动画曲线:Curves.FastOutSwowin,
animationDuration:持续时间(毫秒:1000),
)));
}
}
}),
);

您可以使用
缓存的网络映像
库,该库提供
延迟
占位符
和淡入淡出动画,例如:

  child: new CachedNetworkImage(
             imageUrl: "http://via.placeholder.com/350x150",
             placeholder: new Image.asset('assets/placeholder.jpg'),
             errorWidget: new Icon(Icons.error),
             fit: BoxFit.fill,
             fadeInCurve: Curves.easeIn ,
             fadeInDuration: Duration(seconds: 2),
             fadeOutCurve: Curves.easeOut,
             fadeOutDuration: Duration(seconds: 2),
  )

您可以使用
缓存的网络图像
库,该库提供
延迟
占位符
和淡入淡出动画,例如:

  child: new CachedNetworkImage(
             imageUrl: "http://via.placeholder.com/350x150",
             placeholder: new Image.asset('assets/placeholder.jpg'),
             errorWidget: new Icon(Icons.error),
             fit: BoxFit.fill,
             fadeInCurve: Curves.easeIn ,
             fadeInDuration: Duration(seconds: 2),
             fadeOutCurve: Curves.easeOut,
             fadeOutDuration: Duration(seconds: 2),
  )

我应该把代码放在哪里?旋转木马图像不接受任何内容,也不接受图像。在与
图像
小部件相同的位置,它只是一个自定义的小部件。我将此代码放在哪里?转盘图像不接受任何内容,也不接受图像。在与
图像
小部件相同的位置,它只是一个自定义的图像