Overview
Dismissible 이라는 스와이프 형식의 위젯이다. 한번 봐보자
- Dismissible 이란
- 라이브러리
0. 문서
https://api.flutter.dev/flutter/widgets/Dismissible-class.html
Dismissible class - widgets library - Dart API
A widget that can be dismissed by dragging in the indicated direction. Dragging or flinging this widget in the DismissDirection causes the child to slide out of view. Following the slide animation, if resizeDuration is non-null, the Dismissible widget anim
api.flutter.dev
https://pub.dev/packages/swipe_to
swipe_to | Flutter package
SwipeTo is a wrapper for a chat view widget which can be used initiate callback when user horizontally swipe on it.
pub.dev
1. Dismissible 이란?
스와이프 위젯이다.. 어... 네.. ㅋㅋ.. 옆으로 넘기면 없어지거나 아니면 여러가지 가능합니다.
유심히 봐야 할 부분은 Dismissible 의 key 인데 이곳에는 ValueKey class 가 들어갑니다. ValueKey 는 String 값을 받지만 index 를 넘겨줘도 알아서 String 으로 변환하여 주기 때문에 문제는 없습니다.
한번 봐요
...
class _Home extends StatelessWidget {
const _Home({super.key});
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: buildListView(),
),
);
}
ListView buildListView() {
return ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
// 왠만하면 다른 라이브러리 사용하자 ㅋㅋ
return Dismissible(
// ValueKey 는 String 타입을 받지만 index 라는 숫자도 String 타입으로 변환되어 들어감
key: ValueKey(index),
// 백그라운드 설정
background: Container(
color: Colors.red,
),
// child 필수 값
child: ListTile(
leading: Icon(Icons.account_balance_sharp),
title: Text("번호 : $index"),
),
);
},
);
}
}
2. 다른 라이브러리를 사용해보자
제가 그냥 잠깐 본 라이브러리는 swipe_to 라는 라이브러리 입니다.
문서에 다 있기 때문에 그냥 영상만..
'flutter & dart' 카테고리의 다른 글
flutter & dart - Draggable , DragTarget (0) | 2024.04.01 |
---|---|
flutter & dart - Divider 와 Spacer (0) | 2024.04.01 |
flutter & dart - CustomScrollView (0) | 2024.04.01 |
flutter & dart - SingleChildScrollView (0) | 2024.04.01 |
flutter & dart - BoxConstraints (0) | 2024.04.01 |