The application has a list with drop-down items, as shown in the figure:

Checkbox drop down list
The fact is that according to business logic, it is impossible to select more than one checkbox in one of the lists. How can you make such a condition?

Here is the class code that the drop-down list forms:

class _EntryItemState extends State<EntryItem> { //TODO: Сделать условие для выбора только ОДНОГО чекбокса Entry entry; _EntryItemState(Entry entry){ this.entry = entry; } Widget _buildTiles(Entry root) { if (root.children.isEmpty) return new Column( children: <Widget>[ new CheckboxListTile( title: new Text( root.title, style: new TextStyle(fontSize: 14.0), ), value: root.isChecked, onChanged: (bool value) { setState(() { root.isChecked = value; charactToList(root); }); }, ), new Divider(height: 16.0, indent: 0.0), ], ); // return new Divider(); return new ExpansionTile( key: new PageStorageKey<Entry>(root), title: new Text(root.title), children: root.children.map(_buildTiles).toList() ); } @override Widget build(BuildContext context) { return _buildTiles(entry); } void charactToList (Entry root){ if(root.isChecked){ character.add(root.title); } if(!root.isChecked){ character.remove(root.title); } } } 

Here is the class code for the Entry object:

 class Entry { Entry(this.isChecked, this.title, [this.children = const <Entry>[]]); final String title; List<Entry> children; bool isChecked; } 

And below is an example of a list of objects: List of objects

  • 2
    The radio button is invented just for this. - Enikeyschik
  • not suitable when there are so many levels of attachments of objects and you need to have no more than one choice for each of the lowest levels - Vyacheslav
  • What exactly is not suitable? - Enikeyschik
  • If I use Radio, I will have the opportunity to select only one item, but I need to be able to select 1-16 list items. Maybe I can not just figure it out, do not argue. Therefore, I ask. You suggested, I tried and it does not work out yet - Vyacheslav
  • one
    Radio buttons are combined into groups. In each group, you can select only one item. You need to create a separate group of radio buttons for each subcategory, rather than one single general for everyone (as you probably did, simply replacing one with another in the code). - Enikeyschik

0