我正在尝试使用 Firestore 数据创建分页数据表。我能够创建静态分页数据表,但不知道如何添加 Firestore 数据。
//这是我的代码
import 'package:flutter/material.dart';
class MainCustomers extends StatefulWidget {
@override
_MainCustomersState createState() => _MainCustomersState();
}
class _MainCustomersState extends State<MainCustomers> {
var dts = DTS();
int _rowPerPage = PaginatedDataTable.defaultRowsPerPage;
@override
Widget build(BuildContext context) {
return PaginatedDataTable(
header: Text('Customer List'),
columns: [
DataColumn(label: Text('Name')),
DataColumn(label: Text('Email')),
DataColumn(label: Text('Phone')),
DataColumn(label: Text('Action')),
],
source: dts,
onRowsPerPageChanged: (r){
setState(() {
_rowPerPage = r!;
});
},
rowsPerPage: _rowPerPage,
);
}
}
class DTS extends DataTableSource{
@override
DataRow getRow(int index){
return DataRow.byIndex(cells: [
DataCell(Text("#cell$index")),
DataCell(Text("#cell$index")),
DataCell(Text("#cell$index")),
DataCell(Text("#cell$index")),
]);
}
@override
bool get isRowCountApproximate => true;
@override
int get rowCount => 100;
@override
int get selectedRowCount => 0;
}
//我正在尝试在 DTS 类中获取 firestore 数据,但由于它扩展了 DataTableSource 并且不知道下一步该做什么而被击中。