-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser_list.dart
50 lines (43 loc) · 1.28 KB
/
user_list.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:csv/csv.dart';
class UserNamesTab extends StatefulWidget {
const UserNamesTab({super.key});
@override
_UserNamesTabState createState() => _UserNamesTabState();
}
class _UserNamesTabState extends State<UserNamesTab> {
List<List<dynamic>> users = [];
@override
void initState() {
super.initState();
fetchData();
}
Future<void> fetchData() async {
try {
Response<String> response = await Dio().get(
'https://raw.githubusercontent.com/codeforamerica/ohana-api/master/data/sample-csv/contacts.csv',
);
String? csvData = response.data;
List<List<dynamic>> csvTable = CsvToListConverter().convert(csvData,eol:'\n' );
setState(() {
csvTable.removeAt(0);
users = csvTable;
});
} catch (error) {
print('Error fetching data: $error');
}
}
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: users.length,
itemBuilder: (context, index) {
return ListTile(
title: Text("Name"), // Assuming the name is in the second column
subtitle: Text(users[index][4].toString()), // Assuming the email is in the fifth column
);
},
);
}
}