I create apps that user can load csv file and i want csv data put into map so that i can make delete function or anything else.... Can somebody help me because i been searching for this it show how to convert csv using loadasset bundle i want to do it with pick file from phone storage
example: convert data from a csv to a dynamic List (Flutter)
I/flutter ( 4028): [[No, Name, Code], [1, Ali, A123], [2, Abu, B456], [3, Amir, C789], [4, Safe, D098], [5, Alif, E765 ]]
here my code
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("CSV DATA"),
backgroundColor: Colors.redAccent[400],
),
body: Container(
child: SingleChildScrollView(
child: Column(children: <Widget>[
FutureBuilder(
future: loadingCsvData(path),
builder: (context, AsyncSnapshot<List<dynamic>> snapshot) {
print(snapshot.data.toString());
return snapshot.hasData
? ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: snapshot.data.map((data) {
return Visibility(
visible: visibilityController,
child: //Your card
Card(
child: GestureDetector(
onTap: () {
withInputField(context);
controller.text = data[1];
_controller.text = data[2];
setState(() {});
},
child: ListTile(
title: Text(
data[1].toString(),
style: TextStyle(
fontWeight: FontWeight.bold),
),
subtitle: Text(data[2].toString()),
isThreeLine: true,
trailing: IconButton(
icon: Icon(Icons.delete),
onPressed: () {},
),
),
),
));
}).toList(),
)
: Center(
child: CircularProgressIndicator(),
);
},
),
]),
)),
This my function for file picker
Future<List<List<dynamic>>> loadingCsvData(String path) async {
final csvFile = new File(path).openRead();
return await csvFile
.transform(utf8.decoder)
.transform(
CsvToListConverter(),
)
.toList();
}
EDIT
my fetch data
FutureBuilder(
future: loadingCsvData(path),
builder: (context,
AsyncSnapshot<Map<int, Map<String, dynamic>>> snapshot) {
print(snapshot.data.toString());
return snapshot.hasData
? ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: [
Card(
child: ListTile(
title: Text(userList.toString()),
),
)
],
)
: Center(
child: CircularProgressIndicator(),
);
},
),
is it right to do like this