【发布时间】:2020-11-11 12:58:21
【问题描述】:
有什么方法可以根据 api 的更改为单个列表项(例如容器的发光边框)设置动画?我有一个包含项目价格的列表视图,当价格实时变化时,我想为该特定项目容器设置动画。几个月来我一直在寻找解决方案,但我还没有找到任何解决方案。
StreamBuilder<MyProducts>(
stream: myProductsBloc.subject.stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data.error != null &&
snapshot.data.error.length > 0) {
return ShowError(
error: snapshot.data.error,
onTap: () => myProductsBloc.getMyProducts(),
);
} else if (snapshot.data.data.length == 0) {
return EmptyWidget();
}
return ListView.separated(
separatorBuilder: (context, i) =>
const SizedBox(height: 10),
padding: EdgeInsets.all(10),
itemCount: snapshot.data.data.length,
itemBuilder: (context, i) {
ProductData productData = snapshot.data.data[i];
return GestureDetector(
onTap: () =>
_buildBottomSheet(argument: productData),
child: ProductCard(product: productData));
},
);
} else if (snapshot.hasError) {
return Center(
child: Text('${snapshot.data.error}'),
);
} else {
return Center(
child: LoadingWidget(text: "Fetching products.."));
}
}),
如果api上的价格发生变化,我想为产品卡片的边框设置动画。
【问题讨论】:
-
使用
AnimatedContainer -
我试过了,但它会为列表视图上的所有项目设置动画,而不是一个特定的项目。
-
非常感谢。我没有完全这样做,但我在项目模型中添加了一个元素“动画”作为布尔值。默认情况下它是假的,但是当数据发生变化时,我在模型上注入了真,它现在可以工作了。也许是不好的做法,但它现在有效。
-
当然,欢迎您
标签: flutter dart flutter-animation