Skip to content

PaginatedDataTable does not expose the scroll controller of the SingleChildScrollView that wraps its content #99547

@jofas

Description

@jofas

Use case

Hi,

I want to override the scrolling functionality for a PaginatedDataTable. I'm using flutter web and currently it is not possible to scroll a table horizontally on desktop devices without a scroll pad. So I was trying to enable horizontal scrolling via the arrow left and arrow right keys using a RawKeyboardListener that tells my ScrollController to scroll. Unfortunately, one cannot simply wrap the PaginatedDataTable in a SingleChildScrollView, since it destroys the layout, giving the PaginatedDataTable an unbounded width it cannot handle, since it is trying to fill out the space it has available.

The following code throws an error:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SizedBox(
          width: 200,
          // A `PaginatedDataTable` cannot be wrapped by a
          // `SingleChildScrollView`, because it provides its child
          // with an unbounded width.
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: PaginatedDataTable(
              columns: <DataColumn>[
                DataColumn(
                  label: Text("1"),
                ),
                DataColumn(
                  label: Text("2"),
                ),
              ],
              source: CustomDataSource(),
            ),
          ),
        ),
      ),
    );
  }
}

class CustomDataSource extends DataTableSource {
  @override
  bool get isRowCountApproximate => false;

  @override
  int get rowCount => 1;

  @override
  int get selectedRowCount => 0;

  @override
  DataRow? getRow(int index) {
    return DataRow(

      cells: <DataCell>[
        DataCell(
          Text(
            "Some very long cell that is wider than 200 logical pixels, the size available to the table",
          ),
        ),
        DataCell(
          Text(
            "Same as the first cell, again some very long cell definetly forcing the table to be wider than 200 logical pixels",
          ),
        ),
      ],
    );
  }
}

The error:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
BoxConstraints forces an infinite width.
The offending constraints were:
  BoxConstraints(w=Infinity, 0.0<=h<=Infinity)

The relevant error-causing widget was:
  PaginatedDataTable
  PaginatedDataTable:file:///home/masterusr/src/flutter_issues/pdt_horizontal_scrolling/lib/main.dart:21:20

Proposal

The content of a PaginatedDataTable is wrapped in a SingleChildScrollView (see here).
I propose to add a ScrollController? scrollController parameter to the PaginatedDataTable constructor that is then provided to the SingleChildScrollView. This should allow me and others to override the horizontal scrolling behavior of the contents of a PaginatedDataTable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions