Navigator(
key: navigatorKey,
observers: [_heroController],
onGenerateInitialRoutes: (navigator, initialRoute) => [
MaterialPageRoute(
builder: (context) => Material(
type: MaterialType.transparency,
child: Stack(
children: [
BlocBuilder<GroceryListBloc, GroceryListState>( // The list of grocery lists
cubit: bloc,
buildWhen: (prev, cur) => cur is ListsListModifiedState,
builder: (context, state) {
return ImplicitlyAnimatedList<GroceryList>(
physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
items: bloc.lists,
itemBuilder: (context, anim, item, i) {
return ScaleTransition(
scale: anim,
child: ListsViewItem(
id: item.id,
bloc: bloc,
),
);
},
areItemsTheSame: (a, b) => a.id == b.id,
);
},
),
Positioned( // The button used to create new grocery lists
bottom: 10,
right: 10,
child: FlatButton(
onPressed: () => bloc.addList(GroceryList(title: "New List")),
child: DecoratedBox(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(50),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Icon(
Icons.add_rounded,
size: 40,
),
),
),
),
),
],
),
),
)
],
);
上述代码的解释
我正在制作一个购物清单应用程序。上面的代码是一段代码。ListsViewItem
是一个代表购物清单的小部件,它显示它的名称并在按下它时推送列表的页面。GroceryList
class 是购物清单的模型,用户可以在其中存储项目。GroceryListBloc
是应用程序的主要 BLoC。GroceryListState
是应用程序的所有其他 BLoC 状态类扩展的 BLoC 状态类。ListsListModifiedState
是当包含杂货清单的列表被修改(列表添加、删除、移动)时发出的状态类。BLoC的addList
方法创建添加给定的杂货店 lsitbloc.lists
和发出ListsListModifiedState
。MaterialApp
树中此导航器上方的某处有一个小部件。由于MaterialApp
提供了自己的导航器,因此上面这段代码中的导航器是嵌套的。
问题
如您所见,ScaleTransition
由. 因此,每当我使用上面附加代码中所示的按钮创建一个新的购物清单时,必须重建它的子项,并且新的购物清单必须由, 动画显示,但它没有动画,而是立即看起来好像它不在 a 中但在 a 中。ListsViewItem
ImplicidlyAnimatedList
BlocBbuilder
ImplicitlyAnimatedList
ImplicitlyAnimatedList
Column
我试图做什么
我尝试删除导航器,因此,MaterialPageRoute
它工作得很好:新创建的ImplicitlyAnimatedList
动画的孩子如预期的那样。
问题
我如何使它ImplicitlyAnimatedList
在嵌套导航器中为其子级设置动画?