본문 바로가기
Flutter/Flutter FAQ

Flutter 더 많은 옵션을 위해 스와이프 목록 항목 (플러터), Swipe List Item for more options (Flutter)

by 베타코드 2023. 7. 12.
반응형

질문


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" button on horizontal drag. Picture on the right.

I don't have enough knowledge to use Gestures combined with Animations to create something like this in flutter. Thats why I hope that someone of you can make an example for everyone like me that we can understand how to implement something like this in a ListView.builder.

enter image description here (Source)

An gif example from the macOS mail App:

enter image description here


답변


이런 종류의 레이아웃을 위한 패키지를 만들었습니다: flutter_slidable (기반 아이디어에 대해 Rémi Rousselet에게 감사드립니다)

이 패키지를 사용하면 목록 항목에 대한 문맥적 작업을 쉽게 만들 수 있습니다. 예를 들어, 설명한 종류의 애니메이션을 만들고 싶다면:

Drawer (iOS) animation

다음 코드를 사용합니다:

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: <Widget>[
    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: <Widget>[
    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'),
    ),
  ],
);
반응형

댓글