Skip to content

Instantly share code, notes, and snippets.

@wilburx9
Last active January 16, 2023 07:02
Show Gist options
  • Select an option

  • Save wilburx9/c5b522bdfc2fd8e79e58c60a93a173ab to your computer and use it in GitHub Desktop.

Select an option

Save wilburx9/c5b522bdfc2fd8e79e58c60a93a173ab to your computer and use it in GitHub Desktop.

Revisions

  1. @Wilburt Wilburt revised this gist Oct 21, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dismissible_animated.dart
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ handleDismiss(DismissDirection direction, int index) {
    textColor: Colors.yellow,
    onPressed: () {
    // Deep copy the email
    final copiedEmail = Email.from(swipedEmail);
    final copiedEmail = Email.copy(swipedEmail);
    // Insert it at swiped position and set state
    items.insert(index, copiedEmail);
    // Also insert the item to the AnimatedList
  2. @Wilburt Wilburt created this gist Oct 19, 2019.
    61 changes: 61 additions & 0 deletions dismissible_animated.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    Tween<Offset> _offSetTween = Tween(
    begin: Offset(1, 0),
    end: Offset.zero,
    );
    ...

    @override
    Widget build(BuildContext context) {
    return Scaffold(
    ...
    body: AnimatedList(
    key: _animatedListKey,
    initialItemCount: items.length,
    itemBuilder: (context, index, animation) {
    var item = items[index];
    return FadeTransition(
    opacity: animation,
    child: SlideTransition(
    position: _offSetTween.animate(animation),
    child: Dismissible(
    ...
    ),
    ),
    );
    },
    ),
    );
    }

    handleDismiss(DismissDirection direction, int index) {
    ...

    // Remove it from the list
    items.removeAt(index);
    // Remove it from the animated list
    _animatedListKey.currentState.removeItem(
    index,
    (context, animation) {
    return SizedBox();
    },

    ...
    _scaffoldKey.currentState
    .showSnackBar(
    SnackBar(
    ...
    action: SnackBarAction(
    label: "Undo",
    textColor: Colors.yellow,
    onPressed: () {
    // Deep copy the email
    final copiedEmail = Email.from(swipedEmail);
    // Insert it at swiped position and set state
    items.insert(index, copiedEmail);
    // Also insert the item to the AnimatedList
    _animatedListKey.currentState.insertItem(index);
    }),
    ),
    )
    ...
    }