flutter - How to wait fetching item from BLoC state before running Hero animation?
问题描述
I make an app to learn more about Flutter, RxDart and BLoC pattern. I would to perform a Hero
animation from my ListView to my Details Page.
My problem is that most of my details page is wrapped into a StreamBuilder
because I need to retrieve my item before showing its information, including the image concerned by the Hero
animation.
Because of that the Hero animation can't be triggered.
return Scaffold(
body: StreamBuilder(
stream: eventBloc.eventDetails,
builder: (context, snapshot) {
Event event;
if (snapshot.hasData) {
event = snapshot.data;
return Stack(
children: <Widget>[
Column(children: <Widget>[
Expanded(
child: ListView(
shrinkWrap: true,
children: <Widget>[
_buildEventImage(context, event),
(event.description != null &&
event.description.trim().isNotEmpty)
? _buildDescriptionSection(context, event)
: Container(),
event.hasLocation ? _buildLocationSection(context) : Container()
],
))
]),
]);
}
return Container(child: LoadingIndicatorWidget(visible: true));
Widget _buildEventImage(BuildContext context, Event event) {
//TODO: Fix Hero animation because of state
return Hero(
tag: 'eventImg${event.id}',
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: eventImageProvider(event.image),
alignment: Alignment.topCenter,
fit: BoxFit.cover),
),
);
}
解决方案
推荐阅读
- asp.net - 未处理的拒绝(错误):无法加载“WebPortal”的设置 - ASP.NET Core React
- javascript - 文件上传器的点击功能
- python - SQL Alchemy 在多对多关系中插入数据
- mocking - 具有 clone() 方法的类的 EasyMock 创建模拟失败
- python - Keras 模型不适用于 ValueError:第 0 层期望 0 权重,但保存的权重有 6 个元素
- c++ - 指向 C++ 中的指针的指针
- html - 我应该使用“名称”还是“ID”作为 HTML 锚点?
- react-native - 用 Jest 反应原生测试
- c++ - 为什么在 Xcode 11.3 Step Over(f6) 中作为 Step Into(f7) 工作?
- julia - 对于 Julia 中的自定义类型,我如何阻止“show”打印其完全限定名称?