i'm getting this error 'Invalid value: Not in inclusive range 0..2: 3' trying to display the existing answer as a hint text in the textfield
TextField(
onChanged: (String ansr) {
answers[question] = ansr;
},
onSubmitted: (String ansr) {
_write(answers);
},
controller: myController,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(
color: Color.fromARGB(255, 128, 124, 124),
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(
color: Color.fromARGB(255, 128, 124, 124),
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(
color: Color.fromARGB(255, 128, 124, 124),
),
),
hintText: data[index].answer.isEmpty ? "Write something" : data[index].answer
),
),
here's the whole code: https://pastecode.io/s/z55k699y
CodePudding user response:
You might be using ListView.builder without specifying itemCount parameter.
CodePudding user response:
This might be happening because the list which you are using to show the existing answer. does not have the same length as length of qst map which you are using for ListView.builder.
List<Data> data = [];
and in the hintText you are checking if data[index].answer.isEmpty , when the element does not even exist. Try creating same length of list and map.
Hope this works!