How can i use controllers in radio group in flutter? - flutter

I am trying to get user input data with different types such as text data and radio button grouped data.
In text type inputs, i use TextEditingControllers, for example ;
final quantNumberController = TextEditingController();
String quant = quantNumberController.text;
var data = {'quant': quant, 'capp': capp}
...
Container(
width: 280,
padding: EdgeInsets.all(10.0),
child: TextField(
controller: quantNumberController,
autocorrect: true,
decoration: InputDecoration(hintText: 'Enter location'),
)
),
And i want to receive radio button data like below, but is there any way to use controllers within ListTiles or how can i get user choice to my json data ;
Container(
margin: EdgeInsets.fromLTRB(0, 0, 0, 10),
child: Column(
children: <Widget>[
Text('Location'),
ListTile(
title: const Text('First value'),
leading: Radio(
value: Cap.Cap33,
groupValue: _capp,
onChanged: (Capp value) {
setState(() {
_capp = value;
capp = 'Cap33';
});
},
),
),
ListTile(
title: const Text('Second value'),
leading: Radio(
value: Capp.Cap22,
groupValue: _capp,
onChanged: (Capp value) {
setState(() {
_capp = value;
capp = 'Cap22';
});
},
),
),
ListTile(
title: const Text('Third value'),
leading: Radio(
value: Capp.Cap44,
groupValue: _capp,
onChanged: (Capp value) {
setState(() {
_capp = value;
capp = 'Cap44';
});
},
),
),
],
) ,
),

In your example, the user choice is saved in _capp.
Let's make a new one:
int every_many_days;
RadioListTile<int>(
title: Text('Every Day'),
value: 1,
groupValue: every_many_days,
onChanged: (int value){
setState(() {every_many_days = value;});
},
),
RadioListTile<int>(
title: Text('Every Week'),
value: 7,
groupValue: every_many_days,
onChanged: (int value){
setState(() {every_many_days = value;});
},
),
Now the choice is available in the variable every_many_days, it will be 1 or 7, and you don't need a controller.

Related

Flutter : Right overflowed by 70 pixels

i m new to flutter and am trying to make a Responsive app , i have a textfield and i wanted to add a dropdown list next to it it s working but it shows a error " right overflowed by 150 pixels" even tho i m using the Expanded widget in the child . the error is in both dropdownlists
thank you for ur help in advance
import '../Classes/demandes.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import '../data/menu_item.dart';
import '../Classes/menu.dart';
import '../data/logout.dart';
class Demandes extends StatefulWidget {
#override
_demande createState() => _demande();
}
class _demande extends State<Demandes> {
String dropdownValue = 'Assets';
String dropdownValue1 = 'Locations';
Future<Demandes?> submitData(String description, ASSETNUM, location,
DESCRIPTION_LONGDESCRIPTION) async {
var respone = await http.post(
Uri.parse(
'http://9080/maxrest/rest/mbo/sr/?_lid=azizl&_lpwd=max12345m&_format=json'),
body: {
"description": description,
"ASSETNUM": ASSETNUM,
"location": location,
"DESCRIPTION_LONGDESCRIPTION": DESCRIPTION_LONGDESCRIPTION,
});
var data = respone.body;
print(data);
if (respone.statusCode == 201) {
dynamic responseString = respone.body;
azizFromJson(responseString);
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text("Demande de service Cree")));
} else
return null;
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text("error")));
return null;
}
late Demandes? _demandes;
TextEditingController descriptionController = TextEditingController();
TextEditingController ASSETNUMController = TextEditingController();
TextEditingController locationController = TextEditingController();
TextEditingController DESCRIPTION_LONGDESCRIPTIONController =
TextEditingController();
Widget DescriptionTextField() {
return TextField(
decoration: InputDecoration(
// labelText: "Description",
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
),
controller: descriptionController,
);
}
Widget AssetTextField() {
return TextField(
decoration: InputDecoration(
// labelText: "Asset",
border: OutlineInputBorder(),
),
controller: ASSETNUMController,
);
}
Widget DeatialsTextField() {
return TextField(
decoration: InputDecoration(
// labelText: "Details",
border: OutlineInputBorder(),
),
maxLines: 10,
controller: DESCRIPTION_LONGDESCRIPTIONController,
);
}
Widget LocationTextField() {
return TextField(
decoration: InputDecoration(
// labelText: "Location",
border: OutlineInputBorder(),
),
controller: locationController,
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Creation Demande de service'),
actions: [
PopupMenuButton<MenuItem>(
onSelected: (item) => onSelected(context, item),
itemBuilder: (context) =>
[...MenuItems.itemsFirst.map(buildItem).toList()],
)
],
),
body: ListView(
padding: EdgeInsets.all(8),
// ignore: prefer_const_literals_to_create_immutables
children: [
ListTile(
title: Text("Description"),
),
DescriptionTextField(),
ListTile(
title: Text("Details"),
),
DeatialsTextField(),
ListTile(title: Text("Asset")),
Row(
children: <Widget>[
Expanded(
child: AssetTextField(),
),
const SizedBox(
width: 20,
),
Expanded(
child: DropdownButton<String>(
value: dropdownValue,
icon: const Icon(Icons.arrow_drop_down),
elevation: 16,
style: const TextStyle(color: Colors.blue),
underline: Container(
height: 2,
color: Color.fromARGB(255, 0, 140, 255),
),
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
items: <String>[
'Assets',
'100014 moteur 3',
'100027 Système de freinage 1',
'12500 Overhead Crane #2',
'13110 Feeder System',
'13120 Bottom Sealing System',
'13130 Stripper System',
'13140 Conveyor System- Pkg. Dept.',
'13141 Elevator Rails And Drainpan Assembly',
'13142 Carton Escapement Assembly #2',
'13143 Chain Wash Assembly',
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)),
],
),
ListTile(
title: Text("Location"),
),
Row(
children: <Widget>[
Expanded(
child: LocationTextField(),
),
const SizedBox(
width: 20,
),
Expanded(
child: DropdownButton<String>(
value: dropdownValue1,
icon: const Icon(Icons.arrow_drop_down),
elevation: 16,
style: const TextStyle(color: Colors.blue),
underline: Container(
height: 2,
color: Color.fromARGB(255, 0, 140, 255),
),
onChanged: (String? newValue) {
setState(() {
dropdownValue1 = newValue!;
});
},
items: <String>[
'Locations',
'100014 moteur 3',
'10002 7 Système de freinage 1',
'12500 Overhead Crane #2',
'13110 Feeder System',
'13120 Bottom Sealing System',
'13130 Stripper System',
'13140 Conveyor System- Pkg. Dept.',
'13141 Elevator Rails And Drainpan Assembly',
'13142 Carton Escapement Assembly #2',
'13143 Chain Wash Assembly',
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)),
],
),
const SizedBox(
width: 20,
),
Padding(padding: EdgeInsets.all(10)),
ElevatedButton(
onPressed: (() async {
String description = descriptionController.text;
String ASSETNUM = ASSETNUMController.text;
String location = locationController.text;
String DESCRIPTION_LONGDESCRIPTION =
DESCRIPTION_LONGDESCRIPTIONController.text;
Demandes? data = await submitData(description, ASSETNUM,
location, DESCRIPTION_LONGDESCRIPTION);
setState(() {
_demandes = data;
});
}),
child: Text("submit "),
)
],
));
}
}
Ok the only thing that you have to write is this :
Expanded(
child: DropdownButton<String>(
value: dropdownValue,
isExpanded: true, // this
[...]
),
),
Like the documentation say :
Set the dropdown's inner contents to horizontally fill its parent.
By default this button's inner width is the minimum size of its
contents. If [isExpanded] is true, the inner width is expanded to fill
its surrounding container.

Flutter Dropdownbutton state is not updated - Everything else works fine

I have created a stateful customer information form and the there are two widgets that use the state - two list tiles with radio buttons and a drop down button. The list tiles respond to the code and updates their states and saves the data to the variable as expected.
But the drop down button only saves the value in the assigned variable, but does not display the new value instead of the hint.
I have followed sample code but as I'm new to Flutter I can't find where the mishap might be. Thank you for any help!
The code is as follows; please note that some of the label texts are in my native language and it wouldn't affect code readability. The code in question is in bold (**).
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class CustomerForm extends StatefulWidget {
const CustomerForm({Key key}) : super(key: key);
#override
CustomerFormState createState() {
return CustomerFormState();
}}
class CustomerFormState extends State<CustomerForm> {
final formKey = GlobalKey<FormState>();
String _name = '';
String _age = '';
String _nic = '';
String _sex = '';
String _telephone = '';
String _address = '';
String _email = '';
String _inquiry = '';
**String _branch = '';**
#override
Widget build(BuildContext context) => Scaffold(
resizeToAvoidBottomInset : false,
appBar: AppBar(
title: Text('ඔබේ තොරතුරු පහත පුරවන්න',
style: TextStyle(
fontSize: (20.0),),),
centerTitle: true,
backgroundColor: Colors.cyan,
shadowColor: Colors.tealAccent[50] ),
body:SingleChildScrollView(
child: Form(
key: formKey,
child: Column(children:[
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
autofocus: true,
decoration: InputDecoration(labelText: 'නම'),
validator: (value) {
if (value.isEmpty) {
return 'මෙම තොරතුරු අවශ්‍යයි';}
else if(value.length < 4) {
return 'ඔබ යෙදූ නම කෙටි වැඩි ය.';}
return null;},
onSaved: (value) => _name = value),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
decoration: InputDecoration(labelText: 'වයස (අවු. 18ට වැඩි විය යුතුයි)'),
validator: (value) {
if (value.isEmpty) {
return 'මෙම තොරතුරු අවශ්‍යයි';}
else if (int.parse(value)<18) {
return 'වයස අවුරුදු 18ට වැඩි විය යුතුයි';}
else if (int.parse(value) > 99) {
return 'සැබෑ වයසක් ඇතුළත් කරන්න';}
else {
return null;}},
onSaved: (value) => _age = value),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
decoration: InputDecoration(
labelText: 'ජාතික හැඳුනුම්පත් අංකය'),
validator: (value) {
if (value.isEmpty) {
return 'මෙම තොරතුරු අවශ්‍යයි';}
//TODO finish regexp
String p = r'(^[0-9]v|V|x|X$)';
RegExp regExp = new RegExp(p);
if (regExp.hasMatch(p) && value.length == 10 ) {
return null;}
else
return 'ඇතුළත් කල ජාතික හැඳුනුම්පත් අංකය වලංගු නොවේ';},
onSaved: (value) => _nic = value),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Row(
children:[
SizedBox(
width: 100.0,
child: Text('ස්ත්‍රී / පුරුෂ භාවය :',
style: TextStyle(
color: Colors.black54,
fontSize: 16.0),),
),
Expanded(
child: ListTile(
leading:Radio<String>(
value:'male',
groupValue: _sex,
activeColor: Colors.teal,
onChanged: (value) {
setState(() {_sex = value;});},),
title: const Text('පුරුෂ'),),
),
Expanded(
child: ListTile(
leading:Radio<String>(
value:'female',
groupValue: _sex,
activeColor: Colors.teal,
onChanged: (value) {setState(() {_sex = value;});},),
title: const Text('ස්ත්‍රී'),),),
],
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
decoration: InputDecoration(
labelText: 'දුරකථන අංකය'),
validator: (value) {
String pattern = r'^[0-9]{10}$';
RegExp regExp = new RegExp(pattern);
if (value.length == 0) {
return 'මෙම තොරතුරු අවශ්‍යයි';}
else if (!regExp.hasMatch(value)) {
return 'ඉලක්කම් 10ක් සහිත 0න් ආරම්භ වන වලංගු දුරකථන අංකයක් \n ඇතුළත් කරන්න';}
else {return null;}},
onSaved: (value) => _telephone = value),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
decoration: InputDecoration(
labelText: 'ලිපිනය'),
validator: (value) {
if (value.isEmpty) {
return 'මෙම තොරතුරු අවශ්‍යයි';}
else {return null;}},
onSaved: (value) => _address = value),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
decoration: InputDecoration(
labelText: 'විද්‍යුත් ලිපිනය (තිබේනම්)'),
keyboardType: TextInputType.emailAddress,
validator: (value) {
String p = "[a-zA-Z0-9\+\.\_\%\-\+]{1,256}" +
"\\#" + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + "(" + "\\." +
"[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + ")+";
RegExp regExp = new RegExp(p);
if (value.isNotEmpty && !regExp.hasMatch(value)) {
return 'ඇතුළත් කල විද්‍යුත් ලිපිනය වලංගු නොවේ';}
else
return null;},
onSaved: (value) => _email = value)
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
decoration: InputDecoration(
labelText: 'අමතර කරුණු / විමසීම්'),
onSaved: (value) => _inquiry = value),
),
Padding(padding: const EdgeInsets.fromLTRB(0, 0, 0, 25),),
**DropdownButton<String>(
hint:Text ('ඔබට ළඟම බැංකු ශාඛාව මෙතනින් තෝරන්න.'),
icon: Icon(Icons.arrow_downward),
iconSize: 24, elevation: 16, style: TextStyle(color: Colors.teal),
underline: Container(height: 2, color: Colors.teal,),
onChanged: (String value) {setState(() {_branch = value;});},
items: <String>['Matara', 'Colombo','Galle'].map<DropdownMenuItem<String>>((String value){
return DropdownMenuItem<String>(value:value,
child: Text(value, style: TextStyle(fontSize: 20.0), textAlign: TextAlign.center,));}).toList(),),**
Padding(padding: const EdgeInsets.fromLTRB(0, 0, 0, 45),),
ElevatedButton (
onPressed: () {
if (_sex.isEmpty){
final message = 'ස්ත්‍රි පුරුෂ බව ඇතුළත් කරන්න';
final snackBar = SnackBar(
content: Text(message),
backgroundColor:Colors.redAccent,
duration: Duration(milliseconds: 3000),);
ScaffoldMessenger.of(context).showSnackBar(snackBar);}
else
if (formKey.currentState.validate()){
formKey.currentState.save();
final message = '$_name, විමසීම සාර්ථකයි.';
final snackBar = SnackBar(
content: Text(message),
backgroundColor:Colors.blue,
duration: Duration(milliseconds: 3000),);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
return http.post(
Uri.parse('http://10.0.2.2:5000/api/userdata'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',},
body: jsonEncode(<String, String>{
'name': _name,
'age': _age,
'NIC': _nic,
'sex': _sex,
'tel': _telephone,
'addr': _address,
'email': _email,
'inquiry': _inquiry,
'branch': _branch
})
);
}},
child: Text('ඔබේ විමසීම මෙතැනින් අප වෙත යොමුකරන්න.'),
)
]
),
),
));}
I tried assigining _branch with 'value' of the button and reversing the names, it did not work. Then When I assigned _branch to the value attribute of teh drop down button it seemed to work but an error came on when the screen was reloaded
This might help you out:
DropdownButton(
hint: Text('ඔබට ළඟම බැංකු ශාඛාව මෙතනින් තෝරන්න.'),
icon: Icon(Icons.arrow_downward),
iconSize: 24,
value: _branch,
elevation: 16,
style: TextStyle(color: Colors.teal),
underline: Container(
height: 2,
color: Colors.teal,
),
onChanged: (value) async {
setState(() {
_branch = value;
debugPrint(value);
});
},
items: <String>['Matara', 'Colombo', 'Galle']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(fontSize: 20.0),
textAlign: TextAlign.center,
));
}).toList(),
),
You'vent declared the "value" inside the DropdownButton widget, if you want your text to appear soon as you choose an option from the Dropdown you must use it like this.
I guess if there's a problem after you change it maybe it's not related to dropdownbutton.
This could be very helpful
final List<String> _items = ['Matara', 'Colombo','Galle'];
late String _branch = _items[0]; //Default selected value
DropdownButton(
hint: Text('ඔබට ළඟම බැංකු ශාඛාව මෙතනින් තෝරන්න.'),
icon: Icon(Icons.arrow_downward),
iconSize: 24,
value: _branch,
elevation: 16,
style: TextStyle(color: Colors.teal),
underline: Container(
height: 2,
color: Colors.teal,
),
onChanged: (value) async {
setState(() {
_branch = value;
debugPrint(value);
});
},
items:_items.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(fontSize: 20.0),
textAlign: TextAlign.center,
)
);
}).toList(),
),

How to change default value of dropdownButton in flutter?

I`m creating a dropdown button in flutter, but i have a problem
when i use dropdown it shows the name of the first item but i want to change it(default value) to categories and idk how to do that, also i tried to use hint(as you see in codes)but it didn't work.
here is my codes:
Container(
height: pageHeight / 15,
padding: EdgeInsets.all(20),
child:DropdownButton(
value: _value,
items: const [
DropdownMenuItem(
child: Text("First Item"),
value: 1,
),
DropdownMenuItem(
child: Text("Second Item"),
value: 2,
),
],
onChanged: (value) {
setState(() {
_value = value as int ;
});
},
hint:Text("Select item")
),
)
I want to change this First Item to categories
Make value nullable. DropdownButton can have null value and while it is null it will show hint widget.
int? _value;
DropdownButton(
value: _value,
items: const [
DropdownMenuItem(
child: Text("First Item"),
value: 1,
),
DropdownMenuItem(
child: Text("Second Item"),
value: 2,
),
],
onChanged: (value) {
setState(() {
_value = value as int;
});
},
hint: Text("categories"),
),
Just Asign on initState()
selectedDropDownValue = "categories";
Container(
height: pageHeight / 15,
padding: EdgeInsets.all(20),
child:DropdownButton(
value: _value,
items: const [
DropdownMenuItem(
child: Text("First Item"),
value: 1,
),
DropdownMenuItem(
child: Text("Second Item"),
value: 2,
),
],
value: selectedDropDownValue,
onChanged: (value) {
setState(() {
selectedDropDownValue = value;
});
},
hint:Text("Select item")
),
)

Maintain radiobutton value when navigating to and from page flutter

I have the following radio button and would like to maintain it's value when a user re-navigates to this screen. Currently, when a user goes to another screen and comes back, it default to the pick up option.
I know that this can be achieved by SharedPreferences but I was wondering if there is another way.
enum DeliveryMethod { delivery, pickup }
DeliveryMethod _character = DeliveryMethod.pickup;
children: <Widget>[
Expanded(
child: ListTile(
title: const Text('Please deliver'),
leading: Radio(
value: DeliveryMethod.delivery,
groupValue: _character,
onChanged: (value) {
_character = value;
});
},
),
),
),
Expanded(
child: ListTile(
title: const Text('I will pick up'),
leading: Radio(
value: DeliveryMethod.pickup,
groupValue: _character,
onChanged:
(DeliveryMethod value) {
setState(() {
_character = value;
});
},
),
),
),
]
you can use
Navigator.pop(context,DeliveryMethod.pickup);
and in your screen
delivery = await Navigator.push(...);
you can use NotifierValue to rebuild widget without need to use setState

List view radio buton not selecting when selected

When i run the program on a device when i tick 2nd or 3rd term it does not take effect.
I am developing an Electronic student attendance tracking system so i decided to use a radio to track the term and also use check box to track the attendance that is checked if the student is present and unchecked if the student is not present but when i check the term radio it gives the correct output on the console but does not take effect on the physical screen.
import 'package:flutter/material.dart';
import 'package:atttendance_register/dataFiles/pupils.dart';
import 'package:atttendance_register/dataFiles/attendance.dart';
import 'package:intl/intl.dart';
class attendance extends StatefulWidget {
static Future<void> show(BuildContext context) async {
await Navigator.of(context).push(
MaterialPageRoute(builder: (context)=>attendance(),fullscreenDialog: true),
);
}
#override
_attendanceState createState() => _attendanceState();
}
class _attendanceState extends State<attendance> {
// final List<Pupils> pupils =[
// Pupils('John', ' Doe', 'Brad', 'Male', '001', DateTime.now(), '21'),
// Pupils('Jane', ' Doe', 'Mary', 'Female', '002', DateTime.now(), '21'),
// Pupils('Mohamed', ' James', '', 'Male', '003', DateTime.now(), '33'),
// Pupils('Titus', ' Nabieu', 'Jusu', 'Male', '004', DateTime.now(), '21'),
// Pupils('Steven', ' kai', 'Rogers', 'Male', '005', DateTime.now(), '21'),
// Pupils('Josephine', ' Bah', 'Neneh', 'Female', '006', DateTime.now(), '23')
//
// ];
final List<Attendance> attendance =[
Attendance(false,'John Doe Brad',DateTime.now(),0),
Attendance(true,'Jane Doe Mary',DateTime.now(),2),
Attendance(false,'Mohamed James',DateTime.now(),1),
Attendance(false,'Titus Nabieu Jusu',DateTime.now(),2),
Attendance(false,'Steven kai Rogers',DateTime.now(),2),
Attendance(false,'Josephine Bah Neneh',DateTime.now(),1)
];
bool selectedCheck = false;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Enter Attendance'),
backgroundColor: Colors.blue[900],
),
backgroundColor: Colors.blue[100],
body:Container(
child: ListView.builder(
itemCount:attendance.length,
itemBuilder:(BuildContext context, int index){
int selectedRadio = attendance[index].Term;
bool selectedCheck = attendance[index].attendance;
return Container(
child: Card(
child: Column(
//final pupil =pupils[index];
children: <Widget>[
Text(attendance[index].pupilName),
Text('Select Term'),
Row(
children: <Widget>[
Radio(
value:0,
groupValue: selectedRadio,
activeColor: Colors.blue,
onChanged: (T){
print(T);
setState(() {selectedRadio = T;}
);},
),
new Text(
'1st Term'
),
new Radio(
value: 1,
groupValue: selectedRadio,
activeColor: Colors.blue,
onChanged: (T){
print(T);
setState(() {selectedRadio = T;}
);
},
),
new Text(
'2nd Term'
),
new Radio(
value: 2,
groupValue: selectedRadio,
activeColor: Colors.blue,
onChanged: (T){
print(T);
setState(() {selectedRadio = T;}
);
},
),
new Text(
'3rd Term',
),
],
),
Row(
children: <Widget>[
Checkbox(
value: selectedCheck,
activeColor: Colors.blue,
onChanged: (bool value){
print(value);
setState(() {selectedCheck = value;}
);},
),
new Text(
'Present'
),
],
),
],
),
),
);
} ,),
),
);
}
// Widget pupilsCard(BuildContext context, int index){
// final pupil =pupils[index];
// bool selectedRadio = false;
//
// return Container(
// child: Card(
// child: Column(
// children: <Widget>[
// Text(pupil.FirstName+' '+pupil.OtherName+' '+pupil.LastName),
// Text('Select Term'),
// Row(
// children: <Widget>[
//
//
// ],
// ),
// Checkbox(
// value: selectedRadio,
// activeColor: Colors.blue,
// onChanged: (bool value){
// print(value);
// setState(() {selectedRadio = value;}
// );},
// ),
// new Text(
// 'Present'
//
// ),
// ],
// ),
// ),
// );
// }
}
In the onChanged property of your Radio widgets and your Checkbox widget, you are assigning the user selected value to the variable selectedRadio / selectedCheck and here is the problem, because when the new State is created through setState, the ListView is rebuilding and you are reassigning selectedRadio / selectedCheck the old value of the objects in this lines:
int selectedRadio = attendance[index].Term;
bool selectedCheck = attendance[index].attendance;
So you were not changing the actual value of the objects in the List, but you have too:
onChanged: (T) {
print(T);
setState(() => attendance[index].Term = T);
},
and
onChanged: (value) {
print(value);
setState(() => attendance[index].attendance = value);
},