Skip to content

Instantly share code, notes, and snippets.

@letsar
Last active August 24, 2018 13:38
Show Gist options
  • Save letsar/00362dfa157355410ae4a05678e76199 to your computer and use it in GitHub Desktop.
Save letsar/00362dfa157355410ae4a05678e76199 to your computer and use it in GitHub Desktop.
slidable_in_depth_02
Widget buildStackActions(BuildContext context, SlidableDelegateContext ctx) {
return new Positioned.fill(
child: new LayoutBuilder(builder: (context, constraints) {
final state = ctx.state;
final count = state.actionCount;
final bool showActions = ctx.showActions;
final Animation<double> actionsMoveAnimation =
state.actionsMoveAnimation;
final double actionExtent =
ctx.getMaxExtent(constraints) * state.widget.actionExtentRatio;
final SlideActionDelegate actionDelegate = state.actionDelegate;
final animations = Iterable.generate(count).map((index) {
return new Tween(
begin: -actionExtent,
end: (count - index - 1) * actionExtent,
).animate(actionsMoveAnimation);
}).toList();
return new AnimatedBuilder(
animation: actionsMoveAnimation,
builder: (context, child) {
return new Stack(
children: List.generate(count, (index) {
// For the main actions we have to reverse the order if we want the last item at the bottom of the stack.
int displayIndex = showActions ? count - index - 1 : index;
return ctx.createPositioned(
position: animations[index].value,
extent: actionExtent,
child: actionDelegate.build(context, displayIndex,
actionsMoveAnimation, SlidableRenderingMode.slide),
);
}),
);
});
}),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment