You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: specify a flexible width column for DataTable #51799
Hi @Hixie, I would like to know your opinion on my idea for this issue. It works as expected on my side but I don't know how possible it is and if it has any side effects.
At a glance I would probably make a custom ColumnWidth subclass rather than adding an API to DataTable et al. That minimizes the additional API surface internally, which minimizes the risk of introducing bugs. (Builders can be really tricky to get right because the semantics of when a builder should rebuild are not exactly obvious.)
I don't know if I understand your idea correctly, but I have a new idea. Instead of adding a new API to the DataTable, I added a columnWidth to DataColumn so we can easily create a DataColumn subclass.
At first, I will add a columnWidth to DataColumn with a default null value to keep the old behavior.
@immutableclassDataColumn {
/// Creates the configuration for a column of a [DataTable].constDataColumn({
requiredthis.label,
this.columnWidth,
this.tooltip,
this.numeric =false,
this.onSort,
this.mouseCursor,
this.headingRowAlignment,
});
// ...finalTableColumnWidth? columnWidth;
}
Then, I modify the code to accept the new configuration from:
I think we shouldn’t overwrite the columnWidths because we have a checkbox column that will be inserted into the Table if the showCheckboxColumn is true. So it becomes harder to control how the column width is implemented to avoid conflict between the new and the old DataTable (something like the index with a checkbox column is different from the index without it).
Besides that, we already had the DataColumn to configure the columns, so we can configure the columnWidth easier if it’s here.
I see, I better understand where you're coming from now.
Have you looked at adding a field on DataColumn that takes a TableColumnWidth, and then making the DataTable code use that if provided, and if not, falling back to what it currently does?
The FlexDataColumn and IntrinsicDataColumn are optional subclasses. Those subclasses are extended from the DataColumn, which has the defaults columnWidth = FlexColumnWidth() and columnWidth = IntrinsicColumnWidth().
That seems like a very minor advantage given the additional complexity it introduces (anyone searching for "DataColumn" will now also find these other classes and have to figure out how they work together before they can understand the API).
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.
Activity
lamnhan066 commentedon Oct 5, 2024
Hi @Hixie, I would like to know your opinion on my idea for this issue. It works as expected on my side but I don't know how possible it is and if it has any side effects.
Create a new type:
Add a new parameter to the
DataTable:Modify this code from:
flutter/packages/flutter/lib/src/material/data_table.dart
Lines 1125 to 1129 in 572b1d7
To:
Then we can use it like this to make it flexible for columns 0 and 1:
Hixie commentedon Oct 7, 2024
At a glance I would probably make a custom ColumnWidth subclass rather than adding an API to DataTable et al. That minimizes the additional API surface internally, which minimizes the risk of introducing bugs. (Builders can be really tricky to get right because the semantics of when a builder should rebuild are not exactly obvious.)
lamnhan066 commentedon Nov 1, 2024
Hi @Hixie
I don't know if I understand your idea correctly, but I have a new idea. Instead of adding a new API to the DataTable, I added a
columnWidthto DataColumn so we can easily create a DataColumn subclass.At first, I will add a
columnWidthto DataColumn with a defaultnullvalue to keep the old behavior.Then, I modify the code to accept the new configuration from:
flutter/packages/flutter/lib/src/material/data_table.dart
Lines 1125 to 1129 in 572b1d7
To:
So we can add a custom DataColumn like:
Hixie commentedon Nov 6, 2024
Is there a reason we can't implement this by literally creating a
ColumnWidthsubclass?Hixie commentedon Nov 6, 2024
Sorry, by
ColumnWidthI meantTableColumnWidth: https://main-api.flutter.dev/flutter/rendering/TableColumnWidth-class.htmlHixie commentedon Nov 6, 2024
(It's possible I don't understand what you're trying to do.)
1 remaining item
Hixie commentedon Nov 6, 2024
Oh, I see. Thanks for the explanation, that makes more sense to me now. :-)
Should we just allow DataTable to be given the columnWidths directly, and have that override the default that it generates?
lamnhan066 commentedon Nov 7, 2024
I think we shouldn’t overwrite the
columnWidthsbecause we have a checkbox column that will be inserted into the Table if theshowCheckboxColumnis true. So it becomes harder to control how the column width is implemented to avoid conflict between the new and the old DataTable (something like the index with a checkbox column is different from the index without it).Besides that, we already had the
DataColumnto configure the columns, so we can configure thecolumnWidtheasier if it’s here.Hixie commentedon Nov 18, 2024
I see, I better understand where you're coming from now.
Have you looked at adding a field on DataColumn that takes a TableColumnWidth, and then making the DataTable code use that if provided, and if not, falling back to what it currently does?
lamnhan066 commentedon Nov 18, 2024
@Hixie yes, that’s the flows I added.
Hixie commentedon Nov 19, 2024
In #51799 (comment) it looks like you're also adding new subclasses though? That's the part I don't understand.
lamnhan066 commentedon Nov 19, 2024
@Hixie
The
FlexDataColumnandIntrinsicDataColumnare optional subclasses. Those subclasses are extended from theDataColumn, which has the defaultscolumnWidth = FlexColumnWidth()andcolumnWidth = IntrinsicColumnWidth().So instead of using:
We can use:
Hixie commentedon Nov 19, 2024
That seems like a very minor advantage given the additional complexity it introduces (anyone searching for "DataColumn" will now also find these other classes and have to figure out how they work together before they can understand the API).
lamnhan066 commentedon Nov 20, 2024
Should I open a PR for it without implementing those subclasses?
Hixie commentedon Nov 20, 2024
Worth a try!
Add `columnWidth` Property to `DataTable` for Customizable Column Wid…
github-actions commentedon Dec 6, 2024
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 -vand a minimal reproduction of the issue.