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

Fixes for Tooltip and localizations #866

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
105 changes: 105 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "pluto_grid",
"request": "launch",
"type": "dart"
},
{
"name": "pluto_grid (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "pluto_grid (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "demo",
"cwd": "demo",
"request": "launch",
"type": "dart"
},
{
"name": "demo (profile mode)",
"cwd": "demo",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "demo (release mode)",
"cwd": "demo",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
},
{
"name": "example (profile mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "example (release mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "pluto_grid_export",
"cwd": "packages/pluto_grid_export",
"request": "launch",
"type": "dart"
},
{
"name": "pluto_grid_export (profile mode)",
"cwd": "packages/pluto_grid_export",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "pluto_grid_export (release mode)",
"cwd": "packages/pluto_grid_export",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "example",
"cwd": "packages/pluto_grid_export/example",
"request": "launch",
"type": "dart"
},
{
"name": "example (profile mode)",
"cwd": "packages/pluto_grid_export/example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "example (release mode)",
"cwd": "packages/pluto_grid_export/example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
12 changes: 10 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class _PlutoGridExamplePageState extends State<PlutoGridExamplePage> {
PlutoColumn(
title: 'Age',
field: 'age',
type: PlutoColumnType.number(),
type: PlutoColumnType.number(defaultValue: 11),
),
PlutoColumn(
title: 'Buy',
field: 'buy',
type: PlutoColumnType.bool(),
),
PlutoColumn(
title: 'Role',
Expand Down Expand Up @@ -98,6 +103,7 @@ class _PlutoGridExamplePageState extends State<PlutoGridExamplePage> {
'id': PlutoCell(value: 'user1'),
'name': PlutoCell(value: 'Mike'),
'age': PlutoCell(value: 20),
'buy': PlutoCell(value: false),
'role': PlutoCell(value: 'Programmer'),
'joined': PlutoCell(value: '2021-01-01'),
'working_time': PlutoCell(value: '09:00'),
Expand All @@ -108,7 +114,8 @@ class _PlutoGridExamplePageState extends State<PlutoGridExamplePage> {
cells: {
'id': PlutoCell(value: 'user2'),
'name': PlutoCell(value: 'Jack'),
'age': PlutoCell(value: 25),
'age': PlutoCell(value: null),
'buy': PlutoCell(value: true),
'role': PlutoCell(value: 'Designer'),
'joined': PlutoCell(value: '2021-02-01'),
'working_time': PlutoCell(value: '10:00'),
Expand All @@ -120,6 +127,7 @@ class _PlutoGridExamplePageState extends State<PlutoGridExamplePage> {
'id': PlutoCell(value: 'user3'),
'name': PlutoCell(value: 'Suzi'),
'age': PlutoCell(value: 40),
'buy': PlutoCell(value: null),
'role': PlutoCell(value: 'Owner'),
'joined': PlutoCell(value: '2021-03-01'),
'working_time': PlutoCell(value: '11:00'),
Expand Down
4 changes: 3 additions & 1 deletion lib/src/helper/show_column_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Future<T?>? showColumnMenu<T>({
required BuildContext context,
required Offset position,
required List<PopupMenuEntry<T>> items,
ShapeBorder? shape,
Color backgroundColor = Colors.white,
}) {
final RenderBox overlay =
Expand All @@ -87,6 +88,7 @@ Future<T?>? showColumnMenu<T>({
return showMenu<T>(
context: context,
color: backgroundColor,
shape: shape,
position: RelativeRect.fromLTRB(
position.dx,
position.dy,
Expand All @@ -102,7 +104,7 @@ List<PopupMenuEntry<PlutoGridColumnMenuItem>> _getDefaultColumnMenuItems({
required PlutoGridStateManager stateManager,
required PlutoColumn column,
}) {
final Color textColor = stateManager.style.cellTextStyle.color!;
final Color textColor = stateManager.style.tooltipTextStyle.color!;

final Color disableTextColor = textColor.withOpacity(0.5);

Expand Down
3 changes: 3 additions & 0 deletions lib/src/manager/state/layout_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ mixin LayoutState implements IPlutoGridState {
double get columnHeight =>
showColumnTitle ? configuration.style.columnHeight : 0;

BorderRadiusGeometry? get gridPopupBorderRadius =>
showColumnTitle ? configuration.style.gridPopupBorderRadius : null;

@override
double get columnGroupHeight =>
showColumnGroups ? columnGroupDepth(columnGroups) * columnHeight : 0;
Expand Down
45 changes: 39 additions & 6 deletions lib/src/model/pluto_column_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ abstract class PlutoColumnType {
);
}

/// Set as a bool column.
factory PlutoColumnType.bool() {
return const PlutoColumnTypeBool();
}

/// Set to numeric column.
///
/// [format]
Expand Down Expand Up @@ -255,6 +260,30 @@ class PlutoColumnTypeText implements PlutoColumnType {
}
}

class PlutoColumnTypeBool implements PlutoColumnType {
@override
final dynamic defaultValue;

const PlutoColumnTypeBool({
this.defaultValue,
});

@override
bool isValid(dynamic value) {
return value is bool? || value is bool;
}

@override
int compare(dynamic a, dynamic b) {
return _compareWithNull(a, b, () => a.toString().compareTo(b.toString()));
}

@override
dynamic makeCompareValue(dynamic v) {
return v.toString();
}
}

class PlutoColumnTypeNumber
with PlutoColumnTypeWithNumberFormat
implements PlutoColumnType, PlutoColumnTypeHasFormat<String> {
Expand Down Expand Up @@ -341,7 +370,7 @@ class PlutoColumnTypeCurrency
decimalDigits: decimalDigits,
customPattern: format,
) {
decimalPoint = numberFormat.decimalDigits ?? 0;
decimalPoint = numberFormat.decimalDigits ?? defaultValue;
}

@override
Expand Down Expand Up @@ -550,6 +579,8 @@ mixin PlutoColumnTypeWithNumberFormat {

String? get locale;

dynamic defaultValue;

bool isValid(dynamic value) {
if (!isNumeric(value)) {
return false;
Expand All @@ -571,17 +602,19 @@ mixin PlutoColumnTypeWithNumberFormat {
}

dynamic makeCompareValue(dynamic v) {
return v.runtimeType != num ? num.tryParse(v.toString()) ?? 0 : v;
return v.runtimeType != num
? num.tryParse(v.toString()) ?? defaultValue
: v;
}

String applyFormat(dynamic value) {
num number = num.tryParse(
value.toString().replaceAll(numberFormat.symbols.DECIMAL_SEP, '.'),
) ??
0;
defaultValue;

if (negative == false && number < 0) {
number = 0;
number = defaultValue;
}

return numberFormat.format(number);
Expand All @@ -599,9 +632,9 @@ mixin PlutoColumnTypeWithNumberFormat {
.replaceAll(RegExp('[^$match]'), '')
.replaceFirst(numberFormat.symbols.DECIMAL_SEP, '.');

final num formattedNumber = num.tryParse(formatted) ?? 0;
final num formattedNumber = num.tryParse(formatted) ?? defaultValue;

return formattedNumber.isFinite ? formattedNumber : 0;
return formattedNumber.isFinite ? formattedNumber : defaultValue;
}

bool isNumeric(dynamic s) {
Expand Down
19 changes: 17 additions & 2 deletions lib/src/pluto_grid_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ class PlutoGridStyleConfig {
color: Colors.black,
fontSize: 14,
),
this.tooltipTextStyle = const TextStyle(
color: Colors.black,
fontSize: 14,
),
this.columnContextIcon = Icons.dehaze,
this.columnResizeIcon = Icons.code_sharp,
this.columnAscendingIcon,
Expand Down Expand Up @@ -288,6 +292,10 @@ class PlutoGridStyleConfig {
color: Colors.white,
fontSize: 14,
),
this.tooltipTextStyle = const TextStyle(
color: Colors.white,
fontSize: 14,
),
this.columnContextIcon = Icons.dehaze,
this.columnResizeIcon = Icons.code_sharp,
this.columnAscendingIcon,
Expand Down Expand Up @@ -415,6 +423,9 @@ class PlutoGridStyleConfig {
/// Cell - text style
final TextStyle cellTextStyle;

/// Cell - text style
final TextStyle tooltipTextStyle;

/// Icon that can open a pop-up menu next to the column title
/// when [enableContextMenu] of [PlutoColumn] is true.
final IconData columnContextIcon;
Expand Down Expand Up @@ -481,6 +492,7 @@ class PlutoGridStyleConfig {
EdgeInsets? defaultCellPadding,
TextStyle? columnTextStyle,
TextStyle? cellTextStyle,
TextStyle? tooltipTextStyle,
IconData? columnContextIcon,
IconData? columnResizeIcon,
PlutoOptional<Icon?>? columnAscendingIcon,
Expand Down Expand Up @@ -538,6 +550,7 @@ class PlutoGridStyleConfig {
defaultCellPadding: defaultCellPadding ?? this.defaultCellPadding,
columnTextStyle: columnTextStyle ?? this.columnTextStyle,
cellTextStyle: cellTextStyle ?? this.cellTextStyle,
tooltipTextStyle: tooltipTextStyle ?? this.tooltipTextStyle,
columnContextIcon: columnContextIcon ?? this.columnContextIcon,
columnResizeIcon: columnResizeIcon ?? this.columnResizeIcon,
columnAscendingIcon: columnAscendingIcon == null
Expand Down Expand Up @@ -594,6 +607,7 @@ class PlutoGridStyleConfig {
defaultCellPadding == other.defaultCellPadding &&
columnTextStyle == other.columnTextStyle &&
cellTextStyle == other.cellTextStyle &&
tooltipTextStyle == other.tooltipTextStyle &&
columnContextIcon == other.columnContextIcon &&
columnResizeIcon == other.columnResizeIcon &&
columnAscendingIcon == other.columnAscendingIcon &&
Expand Down Expand Up @@ -639,6 +653,7 @@ class PlutoGridStyleConfig {
defaultCellPadding,
columnTextStyle,
cellTextStyle,
tooltipTextStyle,
columnContextIcon,
columnResizeIcon,
columnAscendingIcon,
Expand Down Expand Up @@ -1192,7 +1207,7 @@ class PlutoGridLocaleText {
this.setFilter = 'Установить фильтр',
this.resetFilter = 'Сбросить фильтр',
// SetColumns popup
this.setColumnsTitle = 'Column title',
this.setColumnsTitle = 'Название колонки',
// Filter popup
this.filterColumn = 'Колонка',
this.filterType = 'Тип',
Expand All @@ -1207,7 +1222,7 @@ class PlutoGridLocaleText {
this.filterLessThan = 'Меньше чем',
this.filterLessThanOrEqualTo = 'Меньше или равно',
// Date popup
this.sunday = 'Вск',
this.sunday = 'Вс',
this.monday = 'Пн',
this.tuesday = 'Вт',
this.wednesday = 'Ср',
Expand Down
Loading