I’m reading data from my db , the specific data in question is a list which was recorded as a String in my database , now i’m trying to read the data by converting the String back into a List , how can i go about doing this wthe snippet of code below :
Widget build(BuildContext context) {
return ref.watch(getDataByIdProvider(widget.ID)).when(
data: (data) => Scaffold(
body: ListView(
children: [
for (int i = 0; i < data.name.length; i++)//The list in question
RadioListTile(
title: Text(
data.name[i].toString(),
),
value: i,
groupValue: _selectedRadio,
onChanged: (value) {
_selectedRadio = value as int?;
}),],
2
Answers
if your string has been separated by ‘,’ character, you can try this way:
in this code, I have split my string by ‘,’ char, so dart lang will create a list of items before each ‘,’ char. you can turn Text widget to your desired one.
One of the solutions is to store your list as a json string using
jsonEncode
andjsonDecode
fromdart:convert