Я хочу воссоздать тот же ящик для своих пользователей. Как это называется и как я могу воссоздать его во Flutter? Я хочу такую же функцию, как в тиндере. Мой пользователь должен иметь возможность выбрать как минимум 3 интересы.
Я провел много исследований, но не могу найти способов воссоздать его.
Вы можете использовать виджет ChoiceChip
с Wrap
. Воспроизвести этот виджет
class MyThreeOptions extends StatefulWidget {
const MyThreeOptions({super.key});
@override
State<MyThreeOptions> createState() => _MyThreeOptionsState();
}
class _MyThreeOptionsState extends State<MyThreeOptions> {
List<int> selectedIndex = [];
@override
Widget build(BuildContext context) {
return Wrap(
spacing: 8,
runSpacing: 8,
children: List<Widget>.generate(
33,
(int index) {
return DecoratedBox(
decoration: BoxDecoration(
border: selectedIndex.contains(index)
? Border.all(
color: Colors.red,
width: 23,
)
: null,
borderRadius: BorderRadius.circular(24)),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: ChoiceChip(
elevation: 4,
selectedColor: Colors.white,
disabledColor: Colors.grey,
label: Text(
'Item $index',
style: selectedIndex.contains(index)
? TextStyle(color: Colors.red)
: null,
),
padding: EdgeInsets.zero,
selected: selectedIndex.contains(index),
onSelected: (bool selected) {
if (selectedIndex.contains(index))
selectedIndex.remove(index);
else
selectedIndex.add(index);
setState(() {});
},
),
),
);
},
).toList(),
);
}
}
ВОТ ЭТО ДА! Спасибо большое!!! Я новичок в флаттере, и мой спринт заканчивается в пятницу, и я не смог найти решения этой проблемы. Спасибо!!