All Projects → luckysmg → Flutter_swipe_action_cell

luckysmg / Flutter_swipe_action_cell

Licence: apache-2.0
A flutter UI package provides ListView leading and trailing swipe action menu.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Flutter swipe action cell

Oneadapter
A Viewholderless Adapter for RecyclerView, who supports builtin diffing, states (paging, empty...), events (clicking, swiping...), and more.
Stars: ✭ 321 (+393.85%)
Mutual labels:  animations, swipe
React Typist
Typing animations with React
Stars: ✭ 1,092 (+1580%)
Mutual labels:  animations
Esp32 Hub75 Driver
A small, simple, passive driver for HUB75 based LED panels
Stars: ✭ 37 (-43.08%)
Mutual labels:  animations
Swipeablecards
Demonstration of draggable transition for UIViewController with swipeable UICollectionView cells inside.
Stars: ✭ 52 (-20%)
Mutual labels:  animations
Allkit
🛠 Async List Layout Kit
Stars: ✭ 40 (-38.46%)
Mutual labels:  animations
React Soft Slider
Simple, fast and impartial slider
Stars: ✭ 54 (-16.92%)
Mutual labels:  swipe
Nativescript Image Swipe
A NativeScript widget to easily 👆 and 🔍 through a list of images
Stars: ✭ 35 (-46.15%)
Mutual labels:  swipe
Androidanimationinterpolator
Based on Article: https://blog.mindorks.com/understanding-interpolators-in-android-ce4e8d1d71cd
Stars: ✭ 65 (+0%)
Mutual labels:  animations
Springbasedsplash
A splash screen made from inspiration of ShowBox app using Physics Based Animation
Stars: ✭ 58 (-10.77%)
Mutual labels:  animations
Material Design Theme
🎨 A ex-theme for Discord according to Google's Material design Guidelines. Now moved to https://github.com/rauenzi/Nox
Stars: ✭ 50 (-23.08%)
Mutual labels:  animations
Ckdcss
A tiny set of micro interactions for your checkboxes.
Stars: ✭ 49 (-24.62%)
Mutual labels:  animations
Redux Actuator
☎️ Communicate between components through Redux store
Stars: ✭ 40 (-38.46%)
Mutual labels:  animations
Rnal
Animations library for react-native
Stars: ✭ 54 (-16.92%)
Mutual labels:  animations
Animate Css Grid
Painless transitions for CSS Grid
Stars: ✭ 987 (+1418.46%)
Mutual labels:  animations
Pullupcontroller
Pull up controller with multiple sticky points like in iOS Maps
Stars: ✭ 1,130 (+1638.46%)
Mutual labels:  swipe
Bluetooth State View
Material design animated Bluetooth state view for Android
Stars: ✭ 36 (-44.62%)
Mutual labels:  animations
Uwp App Launcher Mobile
[Open Source] It's like the iOS and Android Home Screens but for Windows 10 (Phones).
Stars: ✭ 47 (-27.69%)
Mutual labels:  swipe
Rxgesture
RxSwift reactive wrapper for view gestures
Stars: ✭ 1,069 (+1544.62%)
Mutual labels:  swipe
Libanimation Old
Wobbly windows and animations logic split out from Compiz
Stars: ✭ 65 (+0%)
Mutual labels:  animations
React Native Spline Interpolate
Spline interpolation for React Native animations
Stars: ✭ 65 (+0%)
Mutual labels:  animations

Language:

English |中文简体

flutter_swipe_action_cell

A package that can give you a cell that can be swiped ,effect is like iOS native

Get started

The null safety is available from 2.0.0 !

pub home page click here: pub
install:
flutter_swipe_action_cell: ^2.0.0

1.Preview:

Simple delete Perform first action when full swipe
Delete with animation More than one action
Effect like WeChat(confirm delete) Automatically adjust the button width
Effect like WeChat collection Page:Customize your button shape
With leading Action and trailing action
Edit mode

Full example:

Preview (YouTobe video)

And you can find full example code in example page

Attention !! After V1.2.0,many attrs' (name) are changed because of the publishment of leading action button

if you are using this package and you will upgrade to v1.2.0,you should know this.

Class Previous Name Name Today
SwipeActionCell actions trailingActions
SwipeActionCell (class name) SwipeActionEditController (class name) SwipeActionController
SwipeAction leftPadding paddingToBoundary
SwipeAction forceAlignmentLeft forceAlignmentToBoundary

Examples

  • Example 1:Simple delete the item in ListView

  • Tip:put the code in the itemBuilder of your ListView

 SwipeActionCell(
      key: ObjectKey(list[index]),///this key is necessary
      trailingActions: <SwipeAction>[
        SwipeAction(
            title: "delete",
            onTap: (CompletionHandler handler) async {
              list.removeAt(index);
              setState(() {});
            },
            color: Colors.red),
      ],
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text("this is index of ${list[index]}",
            style: TextStyle(fontSize: 40)),
      ),
    );
  • Example 2:Perform first action when full swipe

SwipeActionCell(
      ///this key is necessary
      key: ObjectKey(list[index]),

      ///this is the same as iOS native
      performsFirstActionWithFullSwipe: true,
      trailingActions: <SwipeAction>[
        SwipeAction(
            title: "delete",
            onTap: (CompletionHandler handler) async {
              list.removeAt(index);
              setState(() {});
            },
            color: Colors.red),
      ],
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text("this is index of ${list[index]}",
            style: TextStyle(fontSize: 40)),
      ),
    );
  • Example 3:Delete with animation

SwipeActionCell(
     key: ObjectKey(list[index]),
     performsFirstActionWithFullSwipe: true,
     trailingActions: <SwipeAction>[
       SwipeAction(
           title: "delete",
           onTap: (CompletionHandler handler) async {
             
             /// await handler(true) : will delete this row
             ///And after delete animation,setState will called to 
             /// sync your data source with your UI

             await handler(true);
             list.removeAt(index);
             setState(() {});
           },
           color: Colors.red),
     ],
     child: Padding(
       padding: const EdgeInsets.all(8.0),
       child: Text("this is index of ${list[index]}",
           style: TextStyle(fontSize: 40)),
     ),
   );
  • Example 4:More than one action:

SwipeActionCell(
     key: ObjectKey(list[index]),

     performsFirstActionWithFullSwipe: true,
     trailingActions: <SwipeAction>[
       SwipeAction(
           title: "delete",
           onTap: (CompletionHandler handler) async {
             await handler(true);
             list.removeAt(index);
             setState(() {});
           },
           color: Colors.red),

       SwipeAction(
           widthSpace: 120,
           title: "popAlert",
           onTap: (CompletionHandler handler) async {
             ///false means that you just do nothing,it will close
             /// action buttons by default
             handler(false);
             showCupertinoDialog(
                 context: context,
                 builder: (c) {
                   return CupertinoAlertDialog(
                     title: Text('ok'),
                     actions: <Widget>[
                       CupertinoDialogAction(
                         child: Text('confirm'),
                         isDestructiveAction: true,
                         onPressed: () {
                           Navigator.pop(context);
                         },
                       ),
                     ],
                   );
                 });
           },
           color: Colors.orange),
     ],
     child: Padding(
       padding: const EdgeInsets.all(8.0),
       child: Text(
           "this is index of ${list[index]}",
           style: TextStyle(fontSize: 40)),
     ),
   );
  • Example 5:Delete like WeChat message page(need to confirm it:

return SwipeActionCell(
      key: ValueKey(list[index]),
      performsFirstActionWithFullSwipe: true,
      trailingActions: <SwipeAction>[
        SwipeAction(
          ///
          ///This attr should be passed to first action
          ///
          nestedAction: SwipeNestedAction(title: "确认删除"),
          title: "删除",
          onTap: (CompletionHandler handler) async {
            await handler(true);
            list.removeAt(index);
            setState(() {});
          },
          color: Colors.red,
        ),
        SwipeAction(
            title: "置顶",
            onTap: (CompletionHandler handler) async {
              ///false means that you just do nothing,it will close
              /// action buttons by default
              handler(false);
            },
            color: Colors.grey),
      ],
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text("this is index of ${list[index]}",
            style: TextStyle(fontSize: 40)),
      ),
    );
  • Example 6:Edit mode(just like iOS native effect)

/// To controller edit mode
 SwipeActionEditController controller;

///在initState
@override
  void initState() {
    super.initState();
    controller = SwipeActionController();
  }
///To get the selected rows index
List<int> selectedIndexes = controller.getSelectedIndexes();

///toggleEditingMode
controller.toggleEditingMode()

///startEditMode
controller.startEditingMode()

///stopEditMode
controller.stopEditingMode()

///select cell
controller.selectCellAt(indexPaths:[1,2,3])

controller.deselectCellAt(indexPaths:[1,2,3])

///pass your data length to selectedAll
controller.selectAll(30)

///deselect all cell
controller deselectAll()

ListView.builder(
        itemBuilder: (c, index) {
          return _item(index);
        },
        itemCount: list.length,
      );


 Widget _item(int index) {
     return SwipeActionCell(
       ///controller
       controller: controller,
       ///index is required if you want to enter edit mode
       index: index,
       performsFirstActionWithFullSwipe: true,
       key: ValueKey(list[index]),
       trailingActions: [
         SwipeAction(
             onTap: (handler) async {
               await handler(true);
               list.removeAt(index);
               setState(() {});
             },
             title: "delete"),
       ],
       child: Padding(
         padding: const EdgeInsets.all(15.0),
         child: Text("This is index of ${list[index]}",
             style: TextStyle(fontSize: 35)),
       ),
     );
   }

  • Example 7:customize shape

Widget _item(int index) {
    return SwipeActionCell(
      key: ValueKey(list[index]),
      trailingActions: [
        SwipeAction(
            nestedAction: SwipeNestedAction(
              ///customize your nested action content

              content: Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(30),
                  color: Colors.red,
                ),
                width: 130,
                height: 60,
                child: OverflowBox(
                  maxWidth: double.infinity,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Icon(
                        Icons.delete,
                        color: Colors.white,
                      ),
                      Text('确认删除',
                          style: TextStyle(color: Colors.white, fontSize: 20)),
                    ],
                  ),
                ),
              ),
            ),

            ///you should set the default  bg color to transparent
            color: Colors.transparent,

            ///set content instead of title of icon
            content: _getIconButton(Colors.red, Icons.delete),
            onTap: (handler) async {
              list.removeAt(index);
              setState(() {});
            }),
        SwipeAction(
            content: _getIconButton(Colors.grey, Icons.vertical_align_top),
            color: Colors.transparent,
            onTap: (handler) {}),
      ],
      child: Padding(
        padding: const EdgeInsets.all(15.0),
        child: Text(
            "This is index of ${list[index]},Awesome Swipe Action Cell!! I like it very much!",
            style: TextStyle(fontSize: 25)),
      ),
    );
  }

  Widget _getIconButton(color, icon) {
    return Container(
      width: 50,
      height: 50,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(25),

        ///set you real bg color in your content
        color: color,
      ),
      child: Icon(
        icon,
        color: Colors.white,
      ),
    );
  }

About CompletionHandler in onTap function of SwipeAction

it means how you want control this cell after you tap it. If you don't want any animation,just don't call it and update your data and UI with setState()

If you want some animation:

  • handler(true) : Means this row will be deleted(You should call setState after it)

  • await handler(true) : Means that you will await the animation to complete(you should call setState after it so that you will get an animation)

  • handler(false) : means it will not delete this row.By default,it just close this cell's action buttons.

  • await handler(false) : means it will wait the close animation to complete.

About all parameter:

I wrote them in my code with dart doc comments.You can read them in source code.

Previous Bug List with related issues

  • issue7 (SwipeActionEditController can't delete cells correctly) --> fixed after v1.1.0
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].