I am using the count variable as a record of the index of my List with type TagColumn. In my code, there is a plus button. Every time you press it, it is supposed to check, if you answered the previous text field. If you did, a new TagColumn will be created. In other words, a new text field. However, I am getting a RangeError, while I am using SetState() to update my count.
My code:
class Practice extends StatefulWidget {
@override
_PracticeState createState() => _PracticeState();
}
class _PracticeState extends State<Practice>{
int count = 0;
@override
Widget build(BuildContext context){
List<TagColumn> ok = List.generate(count, (int i) => new TagColumn());
return Scaffold(
backgroundColor: Colors.black,
body: new LayoutBuilder(builder: (context, constraint){
return new Stack(
children: <Widget>[
SingleChildScrollView(
child: SafeArea(
child: new Wrap(
direction: Axis.horizontal,
children: ok,
)
),
),
new Positioned(
child: new Align(
alignment: FractionalOffset.bottomRight,
child: Container(
margin: EdgeInsets.only(bottom: 50.0, right: 40.0),
child: RawMaterialButton(
onPressed: (){
setState(() {
if(count != 0 && ok[count].text.text.isEmpty){
}
else{
count ++;
}
});
},
shape: CircleBorder(),
child: Icon(
Icons.add_circle,
size: 100.0,
color: Color(0xffd3d3d3),
),
)
)
)
)
],
);
}),
);
}
}
The error:
RangeError (index): Invalid value: Only valid value is 0: 1
If you need more context, here is a previous question I had about an early error in my code: Getter _text isn't defined for class TagColumn in Flutter