Is it possible to deselect all items through an event other than click? #15
alaricodev
started this conversation in
General
Replies: 1 comment
-
Hi @alaricodev, of course, it is possible to set the value from outside the widget, you can do something like this: import 'package:flutter/material.dart';
import 'package:choice/choice.dart';
class InlineScrollableX extends StatefulWidget {
const InlineScrollableX({super.key});
@override
State<InlineScrollableX> createState() => _InlineScrollableXState();
}
class _InlineScrollableXState extends State<InlineScrollableX> {
List<String> choices = [
'News',
'Entertainment',
'Politics',
'Automotive',
'Sports',
'Education',
'Fashion',
'Travel',
'Food',
'Tech',
'Science',
'Arts'
];
String? selectedValue;
void setSelectedValue(String? value) {
setState(() => selectedValue = value);
}
@override
Widget build(BuildContext context) {
return Column(
children: [
InlineChoice<String>.single(
clearable: true,
value: selectedValue,
onChanged: setSelectedValue,
itemCount: choices.length,
itemBuilder: (state, i) {
return ChoiceChip(
selected: state.selected(choices[i]),
onSelected: state.onSelected(choices[i]),
label: Text(choices[i]),
);
},
listBuilder: ChoiceList.createWrapped(
spacing: 10,
runSpacing: 10,
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 25,
),
),
),
OutlinedButton(
onPressed: () => setSelectedValue(null),
child: Text('Reset'),
),
],
);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Good morning. I need that when I save the content, automatically all elements are set to false.
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions