|
|
@@ -0,0 +1,84 @@
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:physigo/database.dart';
|
|
|
+
|
|
|
+
|
|
|
+class MyDataTable extends StatefulWidget {
|
|
|
+ const MyDataTable({Key? key}) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ State<MyDataTable> createState() => _MyDataTableState();
|
|
|
+}
|
|
|
+
|
|
|
+class _MyDataTableState extends State<MyDataTable> {
|
|
|
+
|
|
|
+ List userList = [];
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return Scaffold(
|
|
|
+ body: Center(
|
|
|
+ child: buildDataTable(),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ super.initState();
|
|
|
+ fetchUsers();
|
|
|
+ }
|
|
|
+
|
|
|
+ fetchUsers() async{
|
|
|
+ dynamic users = await DatabaseManager().getUsersList();
|
|
|
+
|
|
|
+ if(users == null){
|
|
|
+ print("Wrong");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ setState(() {
|
|
|
+ userList = users;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget buildDataTable() {
|
|
|
+ final columns = ['ID', 'Name', 'points'];
|
|
|
+
|
|
|
+ return DataTable(
|
|
|
+ columns: getColumns(columns),
|
|
|
+ rows: getRows(),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DataColumn> getColumns(List<String> columns) {
|
|
|
+ return columns.map((String column) {
|
|
|
+ return DataColumn(
|
|
|
+ label: Text(column),
|
|
|
+ );
|
|
|
+ }).toList();
|
|
|
+ }
|
|
|
+ List<DataRow> getRows() {
|
|
|
+ List<DataRow> rows = [];
|
|
|
+
|
|
|
+ userList.forEach((user) {
|
|
|
+ rows.add(
|
|
|
+ DataRow(
|
|
|
+ cells: [
|
|
|
+ DataCell(
|
|
|
+ Text("${user["shared_id"]}"),
|
|
|
+ ),
|
|
|
+ DataCell(
|
|
|
+ Text(user["name"]),
|
|
|
+ ),
|
|
|
+ DataCell(
|
|
|
+ Text("${user["total_points"]}"),
|
|
|
+ ),
|
|
|
+ ]
|
|
|
+ )
|
|
|
+ );
|
|
|
+ });
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|