Swipe List Item for more options (Flutter)

后端 未结 4 1338
谎友^
谎友^ 2020-12-22 19:17

Somedays ago I decided to choose an Ui for an app from Pinterest to practice building apps with Flutter but I\'m stuck with the Slider which shows an \"more\" and \"delete\"

4条回答
  •  猫巷女王i
    2020-12-22 19:41

    I created a package for doing this kind of layout: flutter_slidable (Thanks Rémi Rousselet for the based idea)

    With this package it's easier to create contextual actions for a list item. For example if you want to create the kind of animation you described:

    You will use this code:

    new Slidable(
      delegate: new SlidableDrawerDelegate(),
      actionExtentRatio: 0.25,
      child: new Container(
        color: Colors.white,
        child: new ListTile(
          leading: new CircleAvatar(
            backgroundColor: Colors.indigoAccent,
            child: new Text('$3'),
            foregroundColor: Colors.white,
          ),
          title: new Text('Tile n°$3'),
          subtitle: new Text('SlidableDrawerDelegate'),
        ),
      ),
      actions: [
        new IconSlideAction(
          caption: 'Archive',
          color: Colors.blue,
          icon: Icons.archive,
          onTap: () => _showSnackBar('Archive'),
        ),
        new IconSlideAction(
          caption: 'Share',
          color: Colors.indigo,
          icon: Icons.share,
          onTap: () => _showSnackBar('Share'),
        ),
      ],
      secondaryActions: [
        new IconSlideAction(
          caption: 'More',
          color: Colors.black45,
          icon: Icons.more_horiz,
          onTap: () => _showSnackBar('More'),
        ),
        new IconSlideAction(
          caption: 'Delete',
          color: Colors.red,
          icon: Icons.delete,
          onTap: () => _showSnackBar('Delete'),
        ),
      ],
    );
    

提交回复
热议问题