gpt4 book ai didi

dart - 如何在旋转木马 View 中添加 fadeinImage

转载 作者:IT王子 更新时间:2023-10-29 07:12:28 27 4
gpt4 key购买 nike

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

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),
)));
}
}
}),
);

最佳答案

你可以使用cached network image库,它提供了delayplaceholder和fade动画,一个例子:

  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),
)

关于dart - 如何在旋转木马 View 中添加 fadeinImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54720757/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com