Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- pytorch
- 백준
- rao
- Stream
- 파이토치 트랜스포머를 활용한 자연어 처리와 컴퓨터비전 심층학습
- BAEKJOON
- Got
- ARM
- BOF
- 영상처리
- Dreamhack
- llm을 활용 단어장 앱 개발일지
- FastAPI
- system hacking
- Flutter
- Kaggle
- DART
- Algorithm
- study book
- Computer Architecture
- BFS
- bloc
- ML
- MDP
- PCA
- C++
- fastapi를 사용한 파이썬 웹 개발
- Widget
- Image Processing
- MATLAB
Archives
- Today
- Total
Bull
[Flutter:: Widget] ReorderableListView 수동 정렬하기 본문
ReorderableListView
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Reorderable List Demo',
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.amber),
),
home: ReorderableGroupListPage(),
);
}
}
class ReorderableGroupListPage extends StatefulWidget {
@override
_ReorderableGroupListPageState createState() =>
_ReorderableGroupListPageState();
}
class _ReorderableGroupListPageState extends State<ReorderableGroupListPage> {
List<String> groupNames = ['Group A', 'Group B', 'Group C', 'Group D'];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Reorderable List'),
),
body: ReorderableListView(
onReorder: (int oldIndex, int newIndex) {
setState(() {
if (newIndex > oldIndex) {
newIndex -= 1;
}
final String movedGroup = groupNames.removeAt(oldIndex);
groupNames.insert(newIndex, movedGroup);
});
},
children: [
for (final group in groupNames)
ListTile(
key: ValueKey(group),
title: Text(group),
trailing: Icon(Icons.drag_handle),
),
],
),
);
}
}
코드 설명
onReorder
: 사용자가 리스트 항목의 순서를 변경할 때 호출됩니다.oldIndex
와newIndex
를 받아서, 리스트의 순서를 업데이트합니다.- 여기서 newIndex -= 1 부분은 기존 인덱스가 먼저 제거되기 때문에 새로운 인덱스도 1 내려서 입력해야합니다.
children
: 리스트 항목들을 정의하는 부분입니다. 여기서는ListTile
을 사용하여 각 항목을 렌더링하고, 드래그 가능하게ValueKey
를 부여했습니다.- DartPad에서 작동하면 리스트 전체 잡고 움직이는 것이 안된다.
'Software Framework > Flutter' 카테고리의 다른 글
[Flutter::State] RiverPod Tutorial - Getting Started Review (1) | 2024.10.28 |
---|---|
[Flutter::trubleshooting] flutter_launcher_icons black background trubleshooting (android) (0) | 2024.09.29 |
[Flutter] 부모위젯이 자식위젯의 method 호출 방법 (0) | 2024.09.07 |
[Flutter::Widget] Netiveview(ImagePicker)에서 상태 변경으로 이미지가 렌더링될 때 스크롤 하는 방법 (1) | 2024.09.01 |
[Flutter::Widget] StatefulBuilder (0) | 2024.08.27 |