Flutter PaginatedDataTable rowsPerPage

后端 未结 5 622
我寻月下人不归
我寻月下人不归 2021-02-09 10:23

Can flutter PaginatedDataTable rowsPerPage be set to a number not divisible by 10?

UPDATE

Data used b

5条回答
  •  迷失自我
    2021-02-09 10:58

    I'm leaving this for the next guy since I just battled this recently.

    Right now, it seems like PaginatedDataTable has a couple of bugs in it... this is one of them. If the number of data elements doesn't exactly equal the selected number of rows per page, the PaginatedDataTable widget puts in 'filler rows'

    Until this is fixed, I'd recommend taking the flutter PaginatedDataTable widget in the file paginated_data_table.dart and putting it in your project in order to customize it. (you'll have to replace all of the dependencies that aren't found with a simple import 'package:flutter/material.dart';

    In order to limit the number of seen rows, add the lines with // <--- below in the _getRows method seen below:

      List _getRows(int firstRowIndex, int rowsPerPage) {
        final List result = [];
        final int nextPageFirstRowIndex = firstRowIndex + rowsPerPage;
        bool haveProgressIndicator = false;
        for (int index = firstRowIndex; index < nextPageFirstRowIndex; index += 1) {
          if (index < _rowCount) {  // <---
            // This stops "overflow" rows from appearing on the last page.
            DataRow row;
            if (index < _rowCount || _rowCountApproximate) {
              row = _rows.putIfAbsent(index, () => widget.source.getRow(index));
              if (row == null && !haveProgressIndicator) {
                row ??= _getProgressIndicatorRowFor(index);
                haveProgressIndicator = true;
              }
            }
            row ??= _getBlankRowFor(index);
            result.add(row);
          }                      // <---
        }
        return result;
      }
    

    Additionally, the page count will now be off, so you'll have to change this section below in order to add the ternary operator to change the final count:

    Text(
         localizations.pageRowsInfoTitle(
         _firstRowIndex + 1,
         (_firstRowIndex + widget.rowsPerPage <= _rowCount)?_firstRowIndex + widget.rowsPerPage:_rowCount,
         _rowCount,
         _rowCountApproximate,
        ),
      ),
    

提交回复
热议问题