Here how you can creat a radio button in Flutter easily.
Of course, the magic in a radio button is that if you select one, the others in the same group are deselected. So obviously we need to group them somehow. In Flutter, Radio widgets are grouped when you set the groupValue
property to the same local variable. This variable holds the value of the one Radio that is currently turned on.
Each Radio also has its own value property, the value associated with that particular widget whether it is selected or not. In the onChanged
method, you’ll set the groupValue
variable to the radio’s value:
SearchType _searchType; //Other code goes here Radio<SearchType>( groupValue: _searchType, value: SearchType.anywhere, onChanged: (SearchType val) => _searchType = val), const Text('Search anywhere'), Radio<SearchType>( groupValue: _searchType, value: SearchType.text, onChanged: (SearchType val) => _searchType = val), const Text('Search page text'), Radio<SearchType>( groupValue: _searchType, value: SearchType.title, onChanged: (SearchType val) => _searchType = val), const Text('Search page title'),
The code above would create something like this below,
READ MORE ABOUT FLUTTER RADIO BUTTON HERE: https://api.flutter.dev/flutter/material/Radio-class.html