Search code examples
fluttertogglebutton

Flutter Toggle List


I don't know how to create toggle list like this in flutter.

Here is the image of I'm trying to create :

Toggle List in Alert Dialog


Solution

  • You can use RadioListTile()

    enum Fruit { apple, banana }
    
    Fruit? _fruit = Fruit.apple;
    
    RadioListTile<Fruit>(
      title: const Text('Apple'),
      value: Fruit.apple,
      groupValue: _fruit,
      onChanged: (Fruit? value) {
        setState(() {
          _fruit = value;
        });
      },
    )
    
    RadioListTile<Fruit>(
      title: const Text('Banana'),
      value: Fruit.banana,
      groupValue: _fruit,
      onChanged: (Fruit? value) {
        setState(() {
          _fruit = value;
        });
      },
    )