栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flutter PaginatedDataTable rowsPerPage

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flutter PaginatedDataTable rowsPerPage

  import 'package:flutter/material.dart';    class DemoTable extends StatelessWidget {      @override      Widget build(BuildContext context) {        return _DemoTableBody();      }    }    class _DemoTableBody extends StatefulWidget {      @override      __DemoTableBodyState createState() => __DemoTableBodyState();    }    class __DemoTableBodyState extends State<_DemoTableBody> {      int _rowsPerPage = PaginatedDataTable.defaultRowsPerPage;      // A Variable to hold the length of table based on the condition of comparing the actual data length with the PaginatedDataTable.defaultRowsPerPage      int _rowsPerPage1 = PaginatedDataTable.defaultRowsPerPage;      @override      Widget build(BuildContext context) {      //Obtain the data to be displayed from the Derived DataTableSource        var dts = DTS();        // dts.rowcount provides the actual data length, ForInstance, If we have 7 data stored in the DataTableSource Object, then we will get 12 as dts.rowCount       var tableItemsCount = dts.rowCount;        // PaginatedDataTable.defaultRowsPerPage provides value as 10        var defaultRowsPerPage = PaginatedDataTable.defaultRowsPerPage;        // We are checking whether tablesItemCount is less than the defaultRowsPerPage which means we are actually checking the length of the data in DataTableSource with default PaginatedDataTable.defaultRowsPerPage i.e, 10        var isRowCountLessDefaultRowsPerPage = tableItemsCount < defaultRowsPerPage;        // Assigning rowsPerPage as 10 or acutal length of our data in stored in the DataTableSource Object        _rowsPerPage = isRowCountLessDefaultRowsPerPage ? tableItemsCount : defaultRowsPerPage;        return Scaffold(          appBar: AppBar( title: Text("Demo Paginated Table"),          ),          body: SingleChildScrollView( child: PaginatedDataTable(   header: Text('data with 7 rows per page'),   // comparing the actual data length with the PaginatedDataTable.defaultRowsPerPage and then assigning it to _rowPerPage1 variable which then set using the setsState()   onRowsPerPageChanged: isRowCountLessDefaultRowsPerPage // The source of problem!       ? null       : (rowCount) {setState(() {  _rowsPerPage1 = rowCount;});         },   columns: <DataColumn>[     DataColumn(label: Text('row')),     DataColumn(label: Text('name')),   ],   source: dts,   //Set Value for rowsPerPage based on comparing the actual data length with the PaginatedDataTable.defaultRowsPerPage    rowsPerPage:       isRowCountLessDefaultRowsPerPage ? _rowsPerPage : _rowsPerPage1, ),          ),        );      }    }    class DTS extends DataTableSource {      @override      DataRow getRow(int index) {        return DataRow.byIndex(          index: index,          cells: [ DataCell(Text('row #$index')), DataCell(Text('name #$index')),          ],        );      }      @override      int get rowCount => 9; // Manipulate this to which ever value you wish      @override      bool get isRowCountApproximate => false;      @override      int get selectedRowCount => 0;    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/386822.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号