I want to add the date picker value to the List.
When user after select the date, I will calling function [addToDateList] in _AddFieldDynamicItem.
For this function, it will add to list:
List <DateTime> dateList=[];
Which is in _AddFieldDynamicTest
After click "Add another", I don't know why that it only can record the latest picker value.
Did I need to using another storage method such as sql lite or shared preferences?
import 'dart:convert';
import 'package:flutter/material.dart';
class AddFieldDynamicTest extends StatefulWidget {
#override
_AddFieldDynamicTest createState() => _AddFieldDynamicTest();
}
class _AddFieldDynamicTest extends State<AddFieldDynamicTest> {
Map<String, String> _formdata = {};
var _myPets = List<Widget>();
List <DateTime> dateList=[];
int _index = 1;
void _add() {
_myPets = List.from(_myPets)
..add(AddFieldDynamicItem(_index));
setState(() {
_index += 1;
});
}
#override
void initState() {
// TODO: implement initState
super.initState();
_add();
}
addToDateList(DateTime d){
dateList.add(d);
}
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () => getDateList(),
child: Text('Save'),
),
appBar: AppBar(
title: Text('Add Test 2'),
actions: <Widget>[
FlatButton(
child: Text('Add another'),
onPressed: _add,
),
],
),
body: ListView(
children: _myPets,
),
);
}
getDateList(){
print(dateList.length);
}
}
class AddFieldDynamicItem extends StatefulWidget {
AddFieldDynamicItem(this._index);
final int _index;
#override
_AddFieldDynamicItem createState() => _AddFieldDynamicItem(_index);
}
class _AddFieldDynamicItem extends State<AddFieldDynamicItem> {
_AddFieldDynamicItem(this._index);
String _value = '';
final int _index;
List<DateTime> d=[];
Future _selectDate() async {
DateTime picked = await showDatePicker(
context: context,
initialDate: new DateTime.now(),
firstDate: new DateTime(2000),
lastDate: new DateTime(2100)
);
if(picked != null)
_AddFieldDynamicTest().addToDateList(picked);
setState(() {
_value = picked.toString();
});
}
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
new Column(
children: <Widget>[
new Text('$_index . Current Date'),
new Text(_value),
new RaisedButton(onPressed: _selectDate, child: new Text('Date picker'),)
],
)
],
);
}
}
"_AddFieldDynamicTest().addToDateList(picked);" is make new instance.
So, fix like this.
from
_myPets = List.from(_myPets)
..add(AddFieldDynamicItem(_index));
to
_myPets = List.from(_myPets)
..add(AddFieldDynamicItem(_index, addToDateList));
from
AddFieldDynamicItem(this._index);
final int _index;
to
AddFieldDynamicItem(this._index, this.addToDateList);
final int _index;
final Function(DateTime) addToDateList;
from
if(picked != null)
_AddFieldDynamicTest().addToDateList(picked);
to
if (picked != null) widget.addToDateList(picked);
Related
I'm working with Flutter and I have two cards in the home, the first one, I have to show the most recent call that comes to me, and the second card, it should show me the class that is happening according to the current time, however, I want that when my application is minimized or switched, it updates these two cards, where the first card is CardAviso(),
and the second is CardDiarioClasse()
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> with WidgetsBindingObserver {
var loading = false;
final List<HorariosTurma> _list = [];
final List<HorariosTurma> _listCardDiario = [];
String professorNome = "";
_HomeState() {
getProfessorApi();
}
redirectComunicados() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Comunicados(),
),
);
}
getProfessorApi() {
loading = true;
_list.clear();
API.getApiProfessor().then((response) {
if (response.statusCode == 200) {
Map<String, dynamic> professor = jsonDecode(response.body);
List<dynamic> horariosTurma = professor["horariosturma"];
horariosTurma.forEach((value) {
var horarioTurma = HorariosTurma.fromJson(value);
if (horarioTurma.turma != null || horarioTurma.sala != null) {
_list.add(horarioTurma);
}
});
DateTime now = DateTime(DateTime.now().year, DateTime.now().month,
DateTime.now().day, DateTime.now().hour - 3, DateTime.now().minute);
_list.removeWhere(
(element) => (element.sala == null || element.turma == null));
_list.forEach((e) {
DateTime hourInitList = DateTime(
DateTime.now().year,
DateTime.now().month,
DateTime.now().day,
int.parse(e.horaInicio.toString().split(':')[0]),
int.parse(e.horaInicio.toString().split(':')[1]));
DateTime hourFinalList = DateTime(
DateTime.now().year,
DateTime.now().month,
DateTime.now().day,
int.parse(e.horaFinal.toString().split(':')[0]),
int.parse(e.horaFinal.toString().split(':')[1]));
if (now.isAfter(hourInitList) && now.isBefore(hourFinalList)) {
_listCardDiario.add(e);
}
});
}
loading = false;
});
}
#override
build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xffDFE8EC),
drawer: const Navigation(),
appBar: AppBar(
title: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Image.network("https://eemandev.wd7.com.br/img/logo-branco.png",
height: 50)
]),
backgroundColor: const Color(0xff006f99),
toolbarHeight: 70,
actions: [
Padding(
padding: EdgeInsets.only(right: 16),
child: InkWell(
onTap: () => redirectComunicados(),
child: Icon(Icons.mail),
),
)
]),
body: Padding(
padding: const EdgeInsets.all(26.0),
child: ListView(children: const [
CardAviso(),
CardAction(),
CardDiarioClasse(),
Calendario(),
])));
}
}
I've already made several attempts, including in one of the cards I put the life cycle with the codes below, but it doesn't work:
#override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
getHorarioDiaAtual();
}
#override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.inactive) {
setState(() {});
}
super.didChangeAppLifecycleState(state);
}
I am a new starter for flutter, Currently I have a problem that Setstate cannot update the value.
If the user after select the date using date picker, it should be update the "_value" and display under "new Text('Current Date')".
It is successful to Setstate if I separate in Widget build, but it cannot update in List.
Where I got wrong?
import 'dart:convert';
import 'package:flutter/material.dart';
class AddFieldDynamicTest extends StatefulWidget {
#override
_AddFieldDynamicTest createState() => _AddFieldDynamicTest();
}
class _AddFieldDynamicTest extends State<AddFieldDynamicTest> {
Map<String, String> _formdata = {};
var _myPets = List<Widget>();
int _index = 1;
String _value = '';
Future _selectDate() async {
DateTime picked = await showDatePicker(
context: context,
initialDate: new DateTime.now(),
firstDate: new DateTime(2000),
lastDate: new DateTime(2100)
);
if(picked != null) setState(() => _value = picked.toString());
}
void _add() {
int keyValue = _index;
_myPets = List.from(_myPets)
..add(
Column(
key: Key("${keyValue}"),
children: <Widget>[
ListTile(
leading: Text('Pet $_index : '),
title: TextField(
onChanged: (val) => _formdata['pet${keyValue - 1}'] = val,
),
),
ListTile(
leading: Text('Name of Pet $_index : '),
title: TextField(
onChanged: (val) {
_formdata['name${keyValue - 1}'] = val;
},
),
),
new Column(
children: <Widget>[
new Text('Current Date'),
new Text(_value),
new RaisedButton(onPressed: _selectDate, child: new Text('Date picker'),)
],
)
],
));
setState(() => ++_index);
}
#override
void initState() {
// TODO: implement initState
super.initState();
_add();
}
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () => print(json.encode(_formdata)),
child: Text('Save'),
),
appBar: AppBar(
title: Text('Add Test 2'),
actions: <Widget>[
FlatButton(
child: Text('Add another'),
onPressed: _add,
),
],
),
body: ListView(
children: _myPets,
),
);
}
}
In your demo, you use a variable _myPets to store the ListView's children, and at initialization time you add a child into _myPets.
When the "Date Picker" of the child is clicked, the _value is updated and setState is performed, but the data in _myPets remains unchanged, so even if the build is redone, the UI will still remain unchanged.
At this point, if you click "Add Another", a new child will be inserted into _myPets, and since _value has a value, when the build is finished, you will see that the date selected by the last child will be displayed on the new child.
I think you should know more about how setState is used.
The best way to implement this scenario is to have your own setState for each child, as shown below (simplifying your code) :
class AddFieldDynamicTest extends StatefulWidget {
#override
_AddFieldDynamicTest createState() => _AddFieldDynamicTest();
}
class _AddFieldDynamicTest extends State<AddFieldDynamicTest> {
Map<String, String> _formdata = {};
var _myPets = List<Widget>();
int _index = 1;
void _add() {
_myPets = List.from(_myPets)
..add(AddFieldDynamicItem(_index));
setState(() {
_index += 1;
});
}
#override
void initState() {
// TODO: implement initState
super.initState();
_add();
}
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () => print(json.encode(_formdata)),
child: Text('Save'),
),
appBar: AppBar(
title: Text('Add Test 2'),
actions: <Widget>[
FlatButton(
child: Text('Add another'),
onPressed: _add,
),
],
),
body: ListView(
children: _myPets,
),
);
}
}
class AddFieldDynamicItem extends StatefulWidget {
AddFieldDynamicItem(this._index);
final int _index;
#override
_AddFieldDynamicItem createState() => _AddFieldDynamicItem(_index);
}
class _AddFieldDynamicItem extends State<AddFieldDynamicItem> {
_AddFieldDynamicItem(this._index);
String _value = '';
final int _index;
Future _selectDate() async {
DateTime picked = await showDatePicker(
context: context,
initialDate: new DateTime.now(),
firstDate: new DateTime(2000),
lastDate: new DateTime(2100)
);
if(picked != null)
setState(() {
_value = picked.toString();
});
}
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
new Column(
children: <Widget>[
new Text('$_index . Current Date'),
new Text(_value),
new RaisedButton(onPressed: _selectDate, child: new Text('Date picker'),)
],
)
],
);
}
}
When setState is called the framework is notified that the internal state of the object has changed and therefore it might be necessary to rebuild the widget tree. Hence the framework schedules a build for the state.
The build function is called to rebuild the widget tree. However your Text widget [Text(_value)] that you wish to redraw is within a function private function _add(). This function is not called during the build.
However as you have correctly found out that when you place the Text widget Text(_value) within the return of build function it is redrawn everytime setState is called.
I find a hint from this post:
Flutter - Dynamically adding widget that needs to change state as well
They should have their own state
import 'dart:convert';
import 'package:flutter/material.dart';
class AddFieldDynamicTest extends StatefulWidget {
#override
_AddFieldDynamicTest createState() => _AddFieldDynamicTest();
}
class _AddFieldDynamicTest extends State<AddFieldDynamicTest> {
List<Widget> playButtonList;
void initState() {
playButtonList = <Widget>[];
super.initState();
}
var eue='';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Speech Aid'),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
FlatButton(
child: Text('Add Play Button'),
color: Colors.black26,
onPressed: () {
setState(() {
playButtonList.add(PlayButton());
});
},
),
Expanded(
child: ListView.builder(
itemCount: playButtonList.length,
itemBuilder: (context, index) => playButtonList[index],
),
)
],
),
);
}
}
class PlayButton extends StatefulWidget {
#override
_PlayButtonState createState() => _PlayButtonState();
}
class _PlayButtonState extends State<PlayButton> {
int _index = 0;
#override
void initState() {
super.initState();
}
Map<String, dynamic> _formdata={};
var _value='';
#override
Widget build(BuildContext context) {
int keyValue = _index;
return Column(
key: Key("${keyValue}"),
children: <Widget>[
ListTile(
leading: Text('Pet $_index : '),
title: TextField(
onChanged: (val) => _formdata['pet${keyValue - 1}'] = val,
),
),
ListTile(
leading: Text('Name of Pet $_index : '),
title: TextField(
onChanged: (val) {
_formdata['name${keyValue - 1}'] = val;
},
),
),
new Column(
children: <Widget>[
new Text('Current Date'),
new Text(_value),
new RaisedButton(onPressed: _selectDate, child: new Text('Date picker'),)
],
)
],
);
}
Future _selectDate() async {
DateTime picked = await showDatePicker(
context: context,
initialDate: new DateTime.now(),
firstDate: new DateTime(2000),
lastDate: new DateTime(2100)
);
if(picked != null) setState(() => _value = picked.toString());
}
}
I have a ListView.builder that builds a certain amount of widgets depending on user input. Each widget has their own specific name and has a DropDownMenu. I save this value with the corresponding name of the widget. It saves it correctly. However, when I try and read the data and create a new list from it, this error appears: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
'course' is a list. I am using the shared preferences import. When you tap the flat button, it should build the new list, but it is not. Could you explain to me why this is not working please?
This is code in the main app.
void main() {
runApp(Hemis());
}
class Hemis extends StatefulWidget {
#override
_HemisState createState() => _HemisState();
}
class _HemisState extends State<Hemis> {
_read() async {
final prefs = await SharedPreferences.getInstance();
for(int i = 0; i < course.length; i++) {
listMarks[i].name = course[i].name;
listMarks[i].mark = prefs.getInt(course[i].name) ?? 0;
}
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
ListView.builder(
itemCount: course.length,
itemBuilder: (context, index) {
return ModuleListItem(
name: '${course[index].name}',
credits: course[index].credits,
);
},
),
FlatButton(
onPressed: () {
_read();
for(int i = 0; i < course.length; i++) {
print('${listMarks[i].name}: ${listMarks[i].mark}');
}
},
),
],
),
)
)
);
}
}
The widget that is being built.
final percentage = List<String>.generate(100, (i) => "$i");
class ModuleListItem extends StatefulWidget {
const ModuleListItem ({ Key key, this.name, this.credits }): super(key: key);
final String name;
final int credits;
#override
_ModuleListItemState createState() => _ModuleListItemState();
}
class _ModuleListItemState extends State<ModuleListItem> {
String dropdownValue;
bool isSwitched = false;
_save() async {
final prefs = await SharedPreferences.getInstance();
final key = '${widget.name}';
final value = int.parse(dropdownValue);
prefs.setInt(key, value);
print('saved $value');
}
#override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.keyboard_arrow_down),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: percentage.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
Switch(
value: isSwitched,
onChanged: (value) {
setState(() {
isSwitched = value;
if(isSwitched == true) {
_save();
}
print(isSwitched);
});
},
),
],
),
);
}
}
when I click on IconButton() to delete All items from the list movies I can't see that change until I reopen the page again...
anyone know how I could fix
this my infoPage(("class B")):
class InfoPage extends StatefulWidget {
int id;
int pageId;
InfoPage(this.id,this.pageId);
#override
_InfoPageState createState() => _InfoPageState(id,pageId);
}
class _InfoPageState extends State<InfoPage> {
var db = DatabaseHelper();
String title = "";
String about = "";
String rate = "";
String date = "";
int id;
int pageId;
_InfoPageState(this.id,this.pageId);
#override
void initState() {
super.initState();
if(pageId == 1){
_getMovie();
}
}
void _getMovie() async {
Movie thisMovie = await db.getMovie(id);
setState(() {
title = thisMovie.name;
about = thisMovie.description;
rate = thisMovie.rate;
date = thisMovie.date;
});
}
_deleteMovie() async{
await db.deleteMovie(id);
Navigator.pop(context);
setState(() {
CardsListViewState(pageId).deleteAllList();
});
}
#override
Widget build(BuildContext context) {
Navigator.canPop(context);
return Scaffold(
body: Container(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(bottom: 10),
child:Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(),
),
Container(
margin: EdgeInsets.only(right: 10),
child: IconButton(
icon: Icon(Icons.delete,color: Color(0xffFC4D4D),),
onPressed: (){
_deleteMovie();
}
)
)
],
),
)
],
),
),
);
}
}
and this my CardsListView(("class A"))
class CardsListView extends StatefulWidget {
int whereComeFrom;
CardsListView(this.whereComeFrom);
#override
CardsListViewState createState() => CardsListViewState(whereComeFrom);
}
class CardsListViewState extends State<CardsListView> {
int whereComeFrom;
CardsListViewState(this.whereComeFrom);
var db = DatabaseHelper();
List mainList = [];
final List<Movie> movies = <Movie>[];
deleteAllList() async{
await db.deleteMovies();
setState(() {
movies.clear();
});
}
#override
void initState() {
super.initState();
_readUnites();
if(whereComeFrom == 1){
mainList = movies;
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
body:
GridView.count(
crossAxisCount: 3,
addAutomaticKeepAlives: true,
childAspectRatio: (1/1.5),
children: List.generate(mainList.length, (index){
return CardUnite(mainList[index].name,mainList[index].id,whereComeFrom);
})
),
);
}
You can use a callback function from the parent class supplied to the child class.
Remember that functions are first class objects in Dart.
Just pass in a function that calls setState to the child and have the child call that function.
There is no clear answer on how to implement a checkbox tile in a dialog and set the state to work.
A print statement is working in setting the state of the checkbox is not changing, but other statements are working. Where can I find the answer?
I am using a dialog with multiple check boxes for multi select. Is there another of implementing multiselect in Flutter?
child: TextFormField(
decoration: InputDecoration(
labelText: 'Team Leader',
labelStyle: TextStyle(color: Colors.black)),
controller: teamLeaderController,
enabled: false,
style: TextStyle(color: Colors.black),
),
onTap: () {
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return CheckBoxDialog(context, teamLeader,
"Choose Team Leader", teamLeaderController, onSubmit);
});
}),
class CheckBoxState extends State<CheckBoxDialog> {
BuildContext context;
List<String> places;
String title;
TextEditingController con;
bool state;
CheckBoxState(this.context, this.places, this.title, this.con);
#override
void initState() {
super.initState();
state = false;
}
#override
Widget build(BuildContext context) {
return new AlertDialog(
title: new Text(title),
content:
Column(children: getMultiSelectOption(context, places, con, state)),
actions: <Widget>[
FlatButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
}),
FlatButton(
child: Text('Ok'),
onPressed: () {
widget.onSubmit("");
Navigator.of(context).pop();
})
],
);
}
List<Widget> getMultiSelectOption(BuildContext context, List<String> places,
TextEditingController con, bool state) {
List<Widget> options = [];
List<String> selectedList = [];
for (int i = 0; i < places.length; i++) {
options.add(CheckboxListTile(
title: Text(places[i]),
value: selectedList.contains(places[i]),
onChanged: (bool value) {
print("on change: $value title: ${places[i]}");
setState(() {
if (value) {
selectedList.add(places[i]);
} else {
selectedList.remove(places[i]);
}
print("contains: ${selectedList.contains(places[i])}");
print("status: $value");
});
}));
}
return options;
}
}
Suppose you have a Dialog with some Widgets such as RadioListTile, DropdowButton… or anything that might need to be updated WHILE the dialog remains visible, how to do it?
Look at this example here.
https://www.didierboelens.com/2018/05/hint-5-how-to-refresh-the-content-of-a-dialog-via-setstate/
Suppose you have a Dialog with some Widgets such as RadioListTile, DropdowButton… or anything that might need to be updated WHILE the dialog remains visible, how to do it?
Difficulty: Beginner
Background
Lately I had to display a Dialog to let the user select an item from a list and I wanted to display a list of RadioListTile.
I had no problem to show the Dialog and display the list, via the following source code:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class Sample extends StatefulWidget {
#override
_SampleState createState() => new _SampleState();
}
class _SampleState extends State<Sample> {
List<String> countries = <String>['Belgium','France','Italy','Germany','Spain','Portugal'];
int _selectedCountryIndex = 0;
#override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_){_showDialog();});
}
_buildList(){
if (countries.length == 0){
return new Container();
}
return new Column(
children: new List<RadioListTile<int>>.generate(
countries.length,
(int index){
return new RadioListTile<int>(
value: index,
groupValue: _selectedCountryIndex,
title: new Text(countries[index]),
onChanged: (int value) {
setState((){
_selectedCountryIndex = value;
});
},
);
}
)
);
}
_showDialog() async{
await showDialog<String>(
context: context,
builder: (BuildContext context){
return new CupertinoAlertDialog(
title: new Text('Please select'),
actions: <Widget>[
new CupertinoDialogAction(
isDestructiveAction: true,
onPressed: (){Navigator.of(context).pop('Cancel');},
child: new Text('Cancel'),
),
new CupertinoDialogAction(
isDestructiveAction: true,
onPressed: (){Navigator.of(context).pop('Accept');},
child: new Text('Accept'),
),
],
content: new SingleChildScrollView(
child: new Material(
child: _buildList(),
),
),
);
},
barrierDismissible: false,
);
}
#override
Widget build(BuildContext context) {
return new Container();
}
}
I was surprised to see that despite the setState in lines #34-36, the selected RadioListTile was not refreshed when the user tapped one of the items.
Explanation
After some investigation, I realized that the setState() refers to the stateful widget in which the setState is invoked. In this example, any call to the setState() rebuilds the view of the Sample Widget, and not the one of the content of the dialog. Therefore, how to do?
Solution
A very simple solution is to create another stateful widget that renders the content of the dialog. Then, any invocation of the setState will rebuild the content of the dialog.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class Sample extends StatefulWidget {
#override
_SampleState createState() => new _SampleState();
}
class _SampleState extends State<Sample> {
List<String> countries = <String>['Belgium','France','Italy','Germany','Spain','Portugal'];
#override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_){_showDialog();});
}
_showDialog() async{
await showDialog<String>(
context: context,
builder: (BuildContext context){
return new CupertinoAlertDialog(
title: new Text('Please select'),
actions: <Widget>[
new CupertinoDialogAction(
isDestructiveAction: true,
onPressed: (){Navigator.of(context).pop('Cancel');},
child: new Text('Cancel'),
),
new CupertinoDialogAction(
isDestructiveAction: true,
onPressed: (){Navigator.of(context).pop('Accept');},
child: new Text('Accept'),
),
],
content: new SingleChildScrollView(
child: new Material(
child: new MyDialogContent(countries: countries),
),
),
);
},
barrierDismissible: false,
);
}
#override
Widget build(BuildContext context) {
return new Container();
}
}
class MyDialogContent extends StatefulWidget {
MyDialogContent({
Key key,
this.countries,
}): super(key: key);
final List<String> countries;
#override
_MyDialogContentState createState() => new _MyDialogContentState();
}
class _MyDialogContentState extends State<MyDialogContent> {
int _selectedIndex = 0;
#override
void initState(){
super.initState();
}
_getContent(){
if (widget.countries.length == 0){
return new Container();
}
return new Column(
children: new List<RadioListTile<int>>.generate(
widget.countries.length,
(int index){
return new RadioListTile<int>(
value: index,
groupValue: _selectedIndex,
title: new Text(widget.countries[index]),
onChanged: (int value) {
setState((){
_selectedIndex = value;
});
},
);
}
)
);
}
#override
Widget build(BuildContext context) {
return _getContent();
}
}