Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the adaptability of the column title #811

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions demo/lib/screen/development_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -958,17 +958,19 @@ final testColumnsA = [
enableDropToResize: true,
enableAutoEditing: true,
titleTextAlign: PlutoColumnTextAlign.right,
titleSpan: const TextSpan(
children: [
WidgetSpan(
child: Text(
'* ',
style: TextStyle(color: Colors.red),
titleWidget: RichText(
text: const TextSpan(
children: [
WidgetSpan(
child: Text(
'* ',
style: TextStyle(color: Colors.red),
),
alignment: PlaceholderAlignment.bottom,
),
alignment: PlaceholderAlignment.bottom,
),
TextSpan(text: 'column1'),
],
TextSpan(text: 'column1'),
],
),
),
width: 250,
minWidth: 175,
Expand Down
36 changes: 20 additions & 16 deletions demo/lib/screen/feature/add_and_remove_column_row_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ class _AddAndRemoveColumnRowScreenState
type: PlutoColumnType.text(),
readOnly: true,
checkReadOnly: checkReadOnly,
titleSpan: const TextSpan(children: [
WidgetSpan(
child: Icon(
Icons.lock_outlined,
size: 17,
)),
TextSpan(text: 'Id'),
]),
titleWidget: RichText(
text: const TextSpan(children: [
WidgetSpan(
child: Icon(
Icons.lock_outlined,
size: 17,
)),
TextSpan(text: 'Id'),
]),
),
),
PlutoColumn(
title: 'Name',
Expand All @@ -66,14 +68,16 @@ class _AddAndRemoveColumnRowScreenState
]),
enableEditingMode: false,
frozen: PlutoColumnFrozen.end,
titleSpan: const TextSpan(children: [
WidgetSpan(
child: Icon(
Icons.lock,
size: 17,
)),
TextSpan(text: 'Status'),
]),
titleWidget: RichText(
text: const TextSpan(children: [
WidgetSpan(
child: Icon(
Icons.lock,
size: 17,
)),
TextSpan(text: 'Status'),
]),
),
renderer: (rendererContext) {
Color textColor = Colors.black;

Expand Down
26 changes: 14 additions & 12 deletions lib/src/model/pluto_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,24 @@ class PlutoColumn {

EdgeInsets? filterPadding;

/// Customize the column with TextSpan or WidgetSpan instead of the column's title string.
/// Customize the column with a Widget instead of the column's title string.
///
/// ```
/// titleSpan: const TextSpan(
/// children: [
/// WidgetSpan(
/// child: Text(
/// '* ',
/// style: TextStyle(color: Colors.red),
/// titleWidget: RichText(
/// text: const TextSpan(
/// children: [
/// WidgetSpan(
/// child: Text(
/// '* ',
/// style: TextStyle(color: Colors.red),
/// ),
/// ),
/// ),
/// TextSpan(text: 'column title'),
/// ],
/// TextSpan(text: 'column title'),
/// ],
/// ),
/// ),
/// ```
InlineSpan? titleSpan;
Widget? titleWidget;

/// Customisable cell padding.
/// It takes precedence over defaultCellPadding in PlutoGridConfiguration.
Expand Down Expand Up @@ -202,7 +204,7 @@ class PlutoColumn {
this.minWidth = PlutoGridSettings.minColumnWidth,
this.titlePadding,
this.filterPadding,
this.titleSpan,
this.titleWidget,
this.cellPadding,
this.textAlign = PlutoColumnTextAlign.start,
this.titleTextAlign = PlutoColumnTextAlign.start,
Expand Down
39 changes: 18 additions & 21 deletions lib/src/ui/columns/pluto_column_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -532,40 +532,37 @@ class _ColumnTextWidgetState extends PlutoStateWithChange<_ColumnTextWidget> {
}

String? get _title =>
widget.column.titleSpan == null ? widget.column.title : null;
widget.column.titleWidget == null ? widget.column.title : null;

List<InlineSpan> get _children => [
if (widget.column.titleSpan != null) widget.column.titleSpan!,
List<Widget> get _children => [
if (widget.column.titleWidget != null) widget.column.titleWidget!,
if (_isFilteredList)
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: IconButton(
icon: Icon(
Icons.filter_alt_outlined,
color: stateManager.configuration.style.iconColor,
size: stateManager.configuration.style.iconSize,
),
onPressed: _handleOnPressedFilter,
constraints: BoxConstraints(
maxHeight:
widget.height + (PlutoGridSettings.rowBorderWidth * 2),
),
IconButton(
icon: Icon(
Icons.filter_alt_outlined,
color: stateManager.configuration.style.iconColor,
size: stateManager.configuration.style.iconSize,
),
onPressed: _handleOnPressedFilter,
constraints: BoxConstraints(
maxHeight: widget.height + (PlutoGridSettings.rowBorderWidth * 2),
),
),
];

@override
Widget build(BuildContext context) {
return Text.rich(
TextSpan(
text: _title,
children: _children,
),
return DefaultTextStyle(
style: stateManager.configuration.style.columnTextStyle,
overflow: TextOverflow.ellipsis,
softWrap: false,
maxLines: 1,
textAlign: widget.column.titleTextAlign.value,
child: _title != null
? Text(_title!)
: Row(
children: _children,
),
);
}
}