How to get this kind of radio button in flutter - flutter

I am trying to create a gender selection functionality that contains 3 radio buttons. I have done this code but it is not working as I want it.
Radio button container
final _radio_colume_container = Container(
margin: const EdgeInsets.fromLTRB(50, 15, 50, 00),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Gender*',
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
add_radio_button(0, 'Male'),
add_radio_button(1, 'Female'),
add_radio_button(2, 'Others'),
],
),
],
),
);
add_radio_button Method
Row add_radio_button(int btnValue, String title) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Radio(
activeColor: Colors.green,
value: btnValue,
groupValue: -1,
onChanged: _handleradiobutton,
),
Text(title)
],
);
}
I am achieving this
I want to achieve this.

List gender=["Male","Female","Other"];
String select;
Row addRadioButton(int btnValue, String title) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Radio(
activeColor: Theme.of(context).primaryColor,
value: gender[btnValue],
groupValue: select,
onChanged: (value){
setState(() {
print(value);
select=value;
});
},
),
Text(title)
],
);
}
//Use the above widget where you want the radio button
child: Row(
children: <Widget>[
addRadioButton(0, 'Male'),
addRadioButton(1, 'Female'),
addRadioButton(2, 'Others'),
],
),

You should take a look at RadioListTile as it provides a dense property which will help reduce the padding between the button and its title.

After applying some refactoring from #Shubham's answer, presenting a generalized version of the code for multiple purposes.
import 'package:flutter/material.dart';
/// Requires a list of string ['Male','Female','Other'] only once.
class GenderField extends StatelessWidget {
final List<String> genderList;
GenderField(this.genderList);
#override
Widget build(BuildContext context) {
String select;
Map<int, String> mappedGender = genderList.asMap();
return StatefulBuilder(
builder: (_, StateSetter setState) => Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Gender : ',
style: TextStyle(fontWeight: FontWeight.w400),
),
...mappedGender.entries.map(
(MapEntry<int, String> mapEntry) => Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Radio(
activeColor: Theme.of(context).primaryColor,
groupValue: select,
value: genderList[mapEntry.key],
onChanged: (value) => setState(() => select = value),
),
Text(mapEntry.value)
]),
),
],
),
);
}
}
In the main.dart, this widget can be called as
// Some code
Padding(
padding: EdgeInsets.only(bottom: 10),
child: GenderField(['Male','Female','Other'])
)

Padding(
padding: EdgeInsets.only(left: 5, right: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Gender",
style: TextStyle(fontSize: 19),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: ListTile(
title: const Text('M'),
leading: Radio<Gender>(
fillColor:
MaterialStateColor.resolveWith(
(states) => Colors.blue),
value: Gender.male,
groupValue: _gen,
onChanged: (Gender? value) {
setState(() {
_gen = value;
});
},
),
),
),
Expanded(
child: ListTile(
title: const Text('F'),
leading: Radio<Gender>(
fillColor:
MaterialStateColor.resolveWith(
(states) => Colors.blue),
value: Gender.female,
groupValue: _gen,
onChanged: (Gender? value) {
setState(() {
_gen = value;
});
},
),
),
),
Expanded(
child: ListTile(
title: const Text('O'),
leading: Radio<Gender>(
fillColor:
MaterialStateColor.resolveWith(
(states) => Colors.blue),
value: Gender.other,
groupValue: _gen,
onChanged: (Gender? value) {
setState(() {
_gen = value;
});
},
),
),
),
])
])),

Related

How can I save my Radio button value in SharedPreferences?

This my output
when the first time open app should display like this but select one radio button and close open then should display that selected one
EX:- when the user opens the app at the first then should unselect all values, and then the user select grow and click the next button and close the app after reopening again then should display grow as the selected value.
like this
my code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class RadioButtonScreen extends StatefulWidget {
const RadioButtonScreen({Key? key}) : super(key: key);
#override
State<RadioButtonScreen> createState() => _RadioButtonScreenState();
}
class _RadioButtonScreenState extends State<RadioButtonScreen> {
#override
void initState() {
super.initState();
dropdownValueDisease = level;
checkValueDisease();
}
// data which child
// data which child
String? dropdownValueDisease;
// // List of items in our dropdown menu
String level = 'y';
//IF "dropdownValueMembers" is empty pass "which" word as a initial value if al ready selected then pass the shared preference value
checkValueDisease() {
_getDataDisease();
}
_saveDataDisease(String dropdownDiseaseShared) async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
sharedPreferences.setString("Disease", dropdownDiseaseShared);
}
_getDataDisease() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
dropdownValueDisease = sharedPreferences.getString("Disease") ?? level;
setState(() {});
}
//
//
#override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
child: Column(
children: [
SizedBox(
height: height * 0.72,
width: (MediaQuery.of(context).size.width),
child: Column(
children: <Widget>[
const SizedBox(
height: 10,
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
],
),
title: const Text(
"taking",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "talking",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
],
),
title: const Text(
"grow",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "grow",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
],
),
title: const Text(
"listing ",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "listing",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
],
),
title: const Text(
"eye",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "eye",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: ListTile(
minLeadingWidth: 1,
leading: Icon(
Icons.brightness_1,
color: Colors.black,
size: 10.0,
),
title: const Text(
"autism",
style: TextStyle(
fontSize: 13.3, fontWeight: FontWeight.w800),
),
trailing: Radio(
value: "autism",
groupValue: level,
onChanged: (value) {
setState(() {
level = value.toString();
});
},
),
),
),
],
),
],
),
),
Padding(
padding: const EdgeInsets.only(
bottom: 0.0,
),
child: SizedBox(
width: 160.0,
height: 35.0,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: const BorderSide(
color: Colors.blueAccent,
),
),
),
),
onPressed: () {
_saveDataDisease(level);
},
child: const Text('next')),
),
),
],
),
),
);
}
}
You are trying to save dropdownValueDisease but you should save level value:
onPressed: () {
_saveDataDisease(level);
},
also in your _getDataDisease you need pass SharedPreferences value to level not dropdownValueDisease:
_getDataDisease() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
dropdownValueDisease = sharedPreferences.getString("Disease") ?? level;
level = dropdownValueDisease;
setState(() {});
}

Flutter : Dropdown Issues

As soon as I select a value from my dropdown this error appears
'package: flutter/src/material/dropdown.dart/: Failed assertion: line 855 pos 15: 'item == bull || item.isEmpty || value == null|| item.where((DropdownMenuItemitem){ retuen item.value == value;)}.length ==1':There should be exactly one item with [DropdownButton]'s value: Category 1. Either zero or 2 or more [DropdownMenuItem]s were detected with the same value
How can I rectify it?
And here is my code. It would be a great help.
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String valueChoose;
List _listItem = ["Category 1", "Category 2", "Category 3", "Category 4"];
List _listItem1 = [
"Sub Category 1",
"Sub Category 2",
"Sub Category 3",
"Sub Category 4"
];
List _listItem2 = ["CRIS", "ADMINISTRATION", "ZONE", "DEPARTMENT"];
var selectedState;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Feedback"),
centerTitle: true,
leading: IconButton(
onPressed: () {},
icon: Icon(Icons.home),
),
),
body: Container(
child: Center(
child: Form(
autovalidateMode: AutovalidateMode.onUserInteraction,
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text("Category"),
DropdownButton(
hint: Text("Select"),
items: _listItem
.map<DropdownMenuItem<String>>((valueItem) {
return DropdownMenuItem<String>(
value: valueItem,
child: Text(valueItem),
);
}).toList(),
onChanged: (selectedAccountType) {
setState(() {
selectedState = selectedAccountType;
});
},
value: selectedState,
)
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text("SUBCATEGORY"),
DropdownButton(
hint: Text("Select"),
items: _listItem1
.map<DropdownMenuItem<String>>((valueItem1) {
return DropdownMenuItem<String>(
value: valueItem1,
child: Text(valueItem1),
);
}).toList(),
onChanged: (selectedAccountType) {
setState(() {
selectedState = selectedAccountType;
});
},
value: selectedState,
)
],
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text("MARKED TO"),
DropdownButton(
hint: Text("Select"),
items: _listItem2
.map<DropdownMenuItem<String>>((valueItem2) {
return DropdownMenuItem<String>(
value: valueItem2,
child: Text(valueItem2),
);
}).toList(),
onChanged: (selectedAccountType) {
setState(() {
selectedState = selectedAccountType;
});
},
value: selectedState,
)
],
),
SizedBox(height: 10),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.fromLTRB(70, 00, 70, 00),
child: TextField(
decoration: InputDecoration(
hintText: "Describe your problem here.",
),
maxLength: 1000,
maxLines: 5,
),
)
],
),
SizedBox(height: 10),
ButtonTheme(
child: ElevatedButton(
child: Text("Submit"),
onPressed: () {},
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(
horizontal: 25, vertical: 15),
),
),
),
]),
),
),
));
}
}
The first problem is that you are using the selectedState variable for all DropdownMenu widget. And this isn't practical and it could lead to unexpected behavior and bugs. You should define a separate variable for each DropdownMenu.
Another problem is the way you are initializing the selectedState variable.
You are doing this: var selectedState;, without specifying a value so it gets a value of null by default.
However, the initial value of the selectedState varibale has to be one of the options of the DropdownMenu.
For example if these List<String> options = <String>["Option 1", "Option 2", "Option 3", "Option 4"]; are your options for the DropdownMenu, then you would have to initialize the selectedState variable like this for example: var selectedState = "Option 1";.
And the error is gone!

Flutter: How to make my fields required and save my dropdown and text data after the submit button is pressed?

Here is my code. I'm unable to save the responses and even the dropdown and the text fields are not showing the required text and the * sign with them. I can't get how can I save the responses submitted by the user and where to do it and what should I write on the on Pressed function in the submit button to save the responses of all the fields above it.
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
TextEditingController problemBox = TextEditingController();
List _listItem = ["Category 1", "Category 2", "Category 3", "Category 4"];
List _listItem1 = [
"Sub Category 1",
"Sub Category 2",
"Sub Category 3",
"Sub Category 4"
];
List _listItem2 = ["CRIS", "ADMINISTRATION", "ZONE", "DEPARTMENT"];
String dropdownValue;
String holder = '';
void getDropDownItem() {
setState(() {
holder = dropdownValue;
});
}
String dropdownValue1;
String holder1 = '';
void getDropDownItem1() {
setState(() {
holder1 = dropdownValue1;
});
}
String dropdownValue2;
String holder2 = '';
void getDropDownItem2() {
setState(() {
holder2 = dropdownValue2;
});
}
bool autoValidate = true;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: Text("Feedback"),
centerTitle: true,
leading: IconButton(
onPressed: () {},
icon: Icon(Icons.home),
),
),
body: Container(
child: Center(
child: SingleChildScrollView(
child: Form(
autovalidateMode: AutovalidateMode.onUserInteraction,
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text("CATEGORY"),
DropdownButton<String>(
hint: Text("Select"),
value: dropdownValue,
items: _listItem
.map<DropdownMenuItem<String>>((valueItem) {
return DropdownMenuItem<String>(
value: valueItem,
child: Text(valueItem),
);
}).toList(),
onChanged: (value) {
setState(() {
dropdownValue = value;
});
},
)
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text("SUBCATEGORY"),
DropdownButton<String>(
hint: Text("Select"),
value: dropdownValue1,
items: _listItem1
.map<DropdownMenuItem<String>>((valueItem1) {
return DropdownMenuItem<String>(
value: valueItem1,
child: Text(valueItem1),
);
}).toList(),
onChanged: (value) {
setState(() {
dropdownValue1 = value;
});
},
)
],
),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text("MARKED TO"),
DropdownButton<String>(
hint: Text("Select"),
value: dropdownValue2,
items: _listItem2
.map<DropdownMenuItem<String>>((valueItem2) {
return DropdownMenuItem<String>(
value: valueItem2,
child: Text(valueItem2),
);
}).toList(),
onChanged: (value) {
setState(() {
dropdownValue2 = value;
});
},
)
],
),
SizedBox(height: 10),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.fromLTRB(70, 00, 70, 00),
child: TextFormField(
validator: (String value) {
if (value.isEmpty) {
return "Name is required";
}
return null;
},
controller: problemBox,
decoration: InputDecoration(
hintText: "Describe your problem here.",
),
maxLength: 1000,
maxLines: 5,
),
)
],
),
SizedBox(height: 10),
ButtonTheme(
child: ElevatedButton(
child: Text("Submit"),
onPressed: () {
_formKey.currentState.save();
},
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(
horizontal: 25, vertical: 15),
),
),
),
]),
),
),
)));
}
To show the error of the textField check if the Form is validate :
ButtonTheme(
child: ElevatedButton(
child: Text("Submit"),
onPressed: () {
if(
_formKey.currentState.validate() // add this
) {
print(" form is valideate"); // here do what you want when the form is validate :)
}
},
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(
horizontal: 25, vertical: 15),
),
),
)
To validate dropDown , change DropdownButton to DropdownButtonFormField has a property validator –
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Flexible(child: Text("MARKED TO")),
Flexible(
child: DropdownButtonFormField<String>( // change to DropdownButtonFormField
hint: Text("Select"),
value: dropdownValue2,
validator: (value) => value == null ? 'your message' : null,// add validator property
items: _listItem2
.map<DropdownMenuItem<String>>((valueItem2) {
return DropdownMenuItem<String>(
value: valueItem2,
child: Text(valueItem2),
);
}).toList(),
onChanged: (value) {
setState(() {
dropdownValue2 = value;
});
},
),
)
],
),
and for * you can juste add it to required fields
Ex :
RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: 'MARKED TO',
children: <TextSpan>[
TextSpan(
text: '*',
style: TextStyle(color: Colors.red),
),
],
),
)

Cannot replace a string in Dart

I'm re-writing a simple application to calculate averages, however I have a hard time with a TextField.
I set the TextField to be able to replace a comma to a period if a locale is en_US, otherwise it should replace a period to a comma if locale is different than en_US. However, replaceAll() method doesn't seem to work.
Sorry for the code quality, but I will fix it after I see where's the problem.
Code:
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/services.dart';
class ArithmeticAverageScreen extends StatefulWidget {
#override
_ArithmeticAverageScreenState createState() => _ArithmeticAverageScreenState();
}
class _ArithmeticAverageScreenState extends State<ArithmeticAverageScreen> {
var _grades = List<Widget>();
var _textFieldController = TextEditingController();
var _gradesList = List<String>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('arithmetic_average_title').tr(),
),
body: Container(
padding: EdgeInsets.all(16.0),
child: ListView(
children: <Widget>[
Card(
child: Container(
padding: EdgeInsets.symmetric(vertical: 20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
leading: Icon(Icons.help),
title: Text('arithmetic_average_help').tr(),
subtitle: Text('arithmetic_average_help_content').tr(),
)
],
),
)
),
SizedBox(height: 16.0),
Card(
child: Container(
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text('arithmetic_average_your_grades', style: Theme.of(context).textTheme.headline5).tr(),
SizedBox(height: 16.0),
Text('arithmetic_average_grades_one_at_a_time', style: Theme.of(context).textTheme.headline6,).tr(),
SizedBox(height: 16.0),
Row(
children: <Widget>[
Container(
width: 60.0,
child: TextField(
controller: _textFieldController,
inputFormatters: [ WhitelistingTextInputFormatter(RegExp("[0-9,.]")) ],
decoration: InputDecoration(
hintText: '5',
labelText: 'arithmetic_average_grade'.tr()
),
),
),
SizedBox(width: 20.0,),
RaisedButton(
onPressed: () {
if (_textFieldController.text == '') {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text('arithmetic_average_type_number').tr(),
);
}
);
}
else {
String locale = Localizations.localeOf(context).toString();
if (locale == 'en_US') {
if (_textFieldController.text.contains(',')) {
print('True');
_textFieldController.text.replaceAll(',', '.');
}
}
else if (locale == 'pl_PL') {
if (_textFieldController.text.contains('.')) {
_textFieldController.text.replaceAll('.', ',');
}
}
setState(() {
_gradesList.add(_textFieldController.text);
print(_gradesList);
_grades.add(Text(_textFieldController.text));
});
}
},
color: Colors.teal[300],
textColor: Colors.white,
child: Text('arithmetic_average_add_button').tr(),
),
],
),
SizedBox(height: 16.0,),
Wrap(
children: _grades,
),
],
),
),
)
],
),
)
);
}
}
In the following line, you are not updating the text of the text field so replace the following
_textFieldController.text.replaceAll(',', '.');
with this
_textFieldController.text = _textFieldController.text.replaceAll(',', '.')

Flutter one time choice radio buttons

How can i make one time choice custom radio button like in the picture
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
int _selection = 0;
selectTime(int timeSelected) {
setState(() {
_selection = timeSelected;
});
}
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text("Home"),
),
body: Container(
padding: EdgeInsets.all(30),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
InkWell(
onTap: () {
setState(() {
_selection = 1;
});
},
child: Stack(
children: <Widget>[
Container(
height: 40,
width: 150,
color: _selection == 1 ? Colors.green : Colors.white,
),
Row(
children: <Widget>[
Radio(
focusColor: Colors.white,
groupValue: _selection,
onChanged: selectTime,
value: 1,
),
Text(
"11:00 - 12:00",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
],
),
),
InkWell(
onTap: () {
setState(() {
_selection = 2;
});
},
child: Stack(
children: <Widget>[
Container(
height: 40,
width: 150,
color: _selection == 2 ? Colors.green : Colors.white,
),
Row(
children: <Widget>[
Radio(
focusColor: Colors.white,
groupValue: _selection,
onChanged: selectTime,
value: 2,
),
Text(
"12:00 - 13:00",
style: TextStyle(fontWeight: FontWeight.bold),
),
],
),
],
),
)
],
),
],
)),
));
}
}