I am able to show normal text fields on PaginatedDataTable. But I want to show my Firestore fields on PaginatedDataTable as stream builder method. I have searched on internet but I could not find relevant to my requirement. How to get firestore data in to PaginatedDataTable source. Or is there any other way Please let me know. Looking for solution and It is very useful if there is get on tapeable row or selectable row also. I want to fetch data from firestore only not from firebase auth. And I have named the firestore collection name as "users". it my be different also Need help how to do this? if it is not possible in PaginatedDataTable, DataTable also fine.
Below is my example Firestore collection and document structure:
firestore collection name: users
documentID1-
email: 'email1'
name : 'name1'
role : 'role1'
uid : 'uid1'
documentID2-
email: 'email2'
name : 'name2'
role : 'role2'
uid : 'uid2'
(more than 20 documents)
Below is my example code which is normally able to show with normal text:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class AdminDashboard extends StatefulWidget {
const AdminDashboard({Key? key}) : super(key: key);
@override
_AdminDashboardState createState() => _AdminDashboardState();
}
class _AdminDashboardState extends State<AdminDashboard> {
final DataTableSource _allUsers = UsersData();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: PaginatedDataTable(
header: const Text("Header Text"),
rowsPerPage: 9,
columns: const [
DataColumn(label: Text('Uid')),
DataColumn(label: Text('Name')),
DataColumn(label: Text('Email')),
DataColumn(label: Text('Role'))
],
source: _allUsers,
),
),
);
}
}
class UsersData extends DataTableSource {
//final List<Map<String, dynamic>> _allUsers = [{}];
@override
DataRow getRow(int index) {
return DataRow.byIndex(
index: index,
cells: [
DataCell(Text('row #$index')),
DataCell(Text('name #$index')),
DataCell(Text('name #$index')),
DataCell(Text('name #$index')),
],
);
}
@override
bool get isRowCountApproximate => false;
@override
int get rowCount => 9;
@override
int get selectedRowCount => 0;
}
Please find below image of Errors after edited as per @xBurnsed Answer.
