Skip to content

PaginatedDataTable shows "wrong" number of total records in footer on last page #116569

Closed as not planned

Description

@DeddyH

The PaginatedDataTable displays empty rows on the last page, if their remaining number does not fit the height. That's ok for me, but the footer displays e.g. "10 -20 of 15". In my opinion this is confusing, so I suggest the following change in paginated_data_table.dart (line 443):

footerWidgets.addAll(<Widget>[
      Container(width: 32.0),
      Text(
        localizations.pageRowsInfoTitle(
          _firstRowIndex + 1,
          _firstRowIndex + widget.rowsPerPage,
          _rowCount,
          _rowCountApproximate,
        ),
      ),

-->

footerWidgets.addAll(<Widget>[
      Container(width: 32.0),
      Text(
        localizations.pageRowsInfoTitle(
          _firstRowIndex + 1,
          math.min(_firstRowIndex + widget.rowsPerPage, _rowCount),
          _rowCount,
          _rowCountApproximate,
        ),
      ),

Activity

  1. danagbemava-nc commented on Dec 6, 2022

    @danagbemava-nc
    Member

    Reproduces on the latest versions of flutter.

    Screenshot 2022-12-06 at 09 24 50

    code sample
    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          home: DataTableDemo(),
        );
      }
    }
    
    class DataTableDemo extends StatelessWidget {
      const DataTableDemo({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('Data Tables'),
          ),
          body: ListView(
            padding: const EdgeInsets.all(16),
            children: [
              PaginatedDataTable(
                header: const Text('Header Text'),
                rowsPerPage: 4,
                columns: const [
                  DataColumn(label: Text('Header A')),
                  DataColumn(label: Text('Header B')),
                  DataColumn(label: Text('Header C')),
                  DataColumn(label: Text('Header D')),
                ],
                source: _DataSource(context),
              ),
            ],
          ),
        );
      }
    }
    
    class _Row {
      _Row(
        this.valueA,
        this.valueB,
        this.valueC,
        this.valueD,
      );
    
      final String valueA;
      final String valueB;
      final String valueC;
      final int valueD;
    
      bool selected = false;
    }
    
    class _DataSource extends DataTableSource {
      _DataSource(this.context) {
        _rows = <_Row>[
          _Row('Cell A1', 'CellB1', 'CellC1', 1),
          _Row('Cell A2', 'CellB2', 'CellC2', 2),
          // _Row('Cell A3', 'CellB3', 'CellC3', 3),
          // _Row('Cell A4', 'CellB4', 'CellC4', 4),
        ];
      }
    
      final BuildContext context;
      late List<_Row> _rows;
    
      int _selectedCount = 0;
    
      @override
      DataRow? getRow(int index) {
        assert(index >= 0);
        if (index >= _rows.length) return null;
        final row = _rows[index];
        return DataRow.byIndex(
          index: index,
          selected: row.selected,
          onSelectChanged: (bool? value) {
            if (value != null && row.selected != value) {
              _selectedCount += value ? 1 : -1;
              assert(_selectedCount >= 0);
              row.selected = value;
              notifyListeners();
            }
          },
          cells: [
            DataCell(Text(row.valueA)),
            DataCell(Text(row.valueB)),
            DataCell(Text(row.valueC)),
            DataCell(Text(row.valueD.toString())),
          ],
        );
      }
    
      @override
      int get rowCount => _rows.length;
    
      @override
      bool get isRowCountApproximate => false;
    
      @override
      int get selectedRowCount => _selectedCount;
    }
    flutter doctor -v
    [✓] Flutter (Channel stable, 3.3.9, on macOS 13.0.1 22A400 darwin-arm, locale en-GB)
        • Flutter version 3.3.9 on channel stable at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision b8f7f1f986 (2 weeks ago), 2022-11-23 06:43:51 +0900
        • Engine revision 8f2221fbef
        • Dart version 2.18.5
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14B47b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    
    [✓] VS Code (version 1.73.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.54.0
    
    [✓] Connected device (4 available)
        • M2007J20CG (mobile) • 5dd3be00                  • android-arm64  • Android 12 (API 31)
        • Nexus (mobile)      • 00008020-001875E83A38002E • ios            • iOS 16.1.2 20B110
        • macOS (desktop)     • macos                     • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm
        • Chrome (web)        • chrome                    • web-javascript • Google Chrome 108.0.5359.94
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.7.0-3.0.pre.35, on macOS 13.0.1 22A400 darwin-arm64, locale en-GB)
        • Flutter version 3.7.0-3.0.pre.35 on channel master at /Users/nexus/dev/sdks/flutters
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision eaf6254488 (4 hours ago), 2022-12-06 00:39:23 -0500
        • Engine revision 5d8530f790
        • Dart version 2.19.0 (build 2.19.0-463.0.dev)
        • DevTools version 2.20.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14B47b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    
    [✓] VS Code (version 1.73.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.54.0
    
    [✓] Connected device (4 available)
        • M2007J20CG (mobile) • 5dd3be00                  • android-arm64  • Android 12 (API 31)
        • Nexus (mobile)      • 00008020-001875E83A38002E • ios            • iOS 16.1.2 20B110
        • macOS (desktop)     • macos                     • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm64
        • Chrome (web)        • chrome                    • web-javascript • Google Chrome 108.0.5359.94
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Dec 6, 2022
  3. TahaTesser commented on Feb 18, 2023

    @TahaTesser
    Contributor

    duplicate of #80421

  4. github-actions commented on Mar 4, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions