v0.1.1selectable_list
顯示可選擇項目清單的組件。當選取其中一項時,清單中的其他元素會動畫隱藏,僅保留所選項目。
55喜歡 22近 30 天下載150Pub 分數
AndroidiOSWebmacOSWindowsLinux
一個顯示可選擇項目列表的 Flutter 小部件。
{"sdk":"flutter"}{"sdk":"flutter"}^2.0.0以下為英文專案原文快照,最新內容請造訪 GitHub。
A widget displaying a list of selectable items
When one of the items is selected, the other elements of the list are animated out, leaving the selected value. When tapping on the value again, the other values are animated back into the list.
Example app
Use this package when you want to allow the user to choose one element in a list, and only show this element when selected.
Based on the Flutter AnimatedList widget
Import the package
import 'package:selectable_list/selectable_list.dart';
Use the widget
class _ScrollableListExampleState extends State<_ScrollableListExample> {
final persons = [
Person("Ella", 3),
Person("James", 25),
Person("Gertrude", 99)
];
String? selectedName;
@override
Widget build(BuildContext context) {
return SelectableList<Person, String?>(
items: persons,
itemBuilder: (context, person, selected, onTap) => ListTile(
title: Text(person.name),
subtitle: Text('${person.age.toString()} years old'),
selected: selected,
onTap: onTap),
valueSelector: (person) => person.name,
selectedValue: selectedName,
onItemSelected: (person) =>
setState(() => selectedName = person.name),
onItemDeselected: (person) => setState(() => selectedName = null),
),
}
}
Useful to make forms cleaner and more compact on mobile
Example in a form