如何解决如何在 Flutter 的 PaginatedDataTable 中使用 DataRows 列表?
我有一个 DataTable
,用户可以在其中动态添加和删除 DaTarow。因此,DataTable 会变得非常大。为了提高性能,我想使用 PaginatedDataTable。但是这个 Widget 需要一个额外的数据源类。
其基本代码如下所示:
class DataSource extends DataTableSource {
int _selectedCount = 0;
@override
int get rowCount => list.length;
@override
bool get isRowCountApproximate => false;
@override
int get selectedRowCount => _selectedCount;
@override
DaTarow getRow(int index) {
return DaTarow.byIndex(
index: index,cells: <DataCell>[
DataCell(Text('1')),DataCell(Text('2')),DataCell(Text('3')),DataCell(Text('4')),]);
}
}
在我的旧代码中,我使用了一个 DataTable,其中我将所有 DaTarow 放在一个列表中,并且运行良好。以下是包含列表的代码片段:
class ExerciseTable extends StatefulWidget {
@override
_ExerciseTableState createState() => _ExerciseTableState();
}
class _ExerciseTableState extends State<ExerciseTable> {
ExerciseDataSource _rowsDataSource;
List<DaTarow> _rowList = [
DaTarow(cells: <DataCell>[
DataCell(Text('1')),]),];
void _addRow() {
_rowList.insert(0,DaTarow(cells: <DataCell>[
DataCell(Text('1')),])
);
}
void _removeRow() {
setState(() {
_rowList.removeAt(0);
});
}
现在我想对 PaginatedDataTable 的 DaTarows 使用相同的列表,但是如何将列表集成到“DataSource”类中? 我很感激每一个答案,如果有人知道怎么做那就太好了:)
解决方法
根据海关需求集成 PaginatedDataTable 可能有点令人困惑,但您可以将数据源列表传递给 DataSource 类(通过构造函数),并在 getRow 方法上,使用索引可以遍历数据。>
一个例子可能是:
@Override
DataRow getRow(int index) {
final currentData = yourDataList[index]
return DataRow.byIndex(
index: index,cells: <DataCell>[
DataCell(Text('${currentData.name}'},],);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。