From 147f6df8473be4b58d8b08544516a0344f1799f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Pedersen?= Date: Sun, 22 Sep 2024 15:37:23 +0200 Subject: [PATCH] Fixed sorting bug in table tab (#280) * Fixed sorting bug in table tab * Bump v0.7.4+33 --- lib/widgets/table.dart | 30 ++++-------------------------- pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/lib/widgets/table.dart b/lib/widgets/table.dart index 5020284..3d40394 100644 --- a/lib/widgets/table.dart +++ b/lib/widgets/table.dart @@ -214,18 +214,6 @@ class _TableWidgetState extends State { } void _sortTable(String column) { - double horizontalScrollPosition = 0.0; - double verticalScrollPosition = 0.0; - - // Check if the scroll controllers are attached to any scroll views - if (_horizontalScrollController.hasClients) { - horizontalScrollPosition = _horizontalScrollController.position.pixels; - } - if (_verticalScrollController.hasClients) { - verticalScrollPosition = _verticalScrollController.position.pixels; - } - - // Sort the data directly setState(() { if (_sortColumn == column) { _sortAscending = !_sortAscending; @@ -237,25 +225,15 @@ class _TableWidgetState extends State { // Perform the sorting on the data _data.sort((a, b) { int compareResult; - if (_sortColumn == 'columnName') { - compareResult = a['columnName'].compareTo(b['columnName']); + if (column == 'exercise' || column == 'timestamp') { + compareResult = a[column].compareTo(b[column]); } else { - // Add more sorting logic for other columns if needed - compareResult = 0; + compareResult = double.parse(a[column].toString()) + .compareTo(double.parse(b[column].toString())); } return _sortAscending ? compareResult : -compareResult; }); }); - - // Restore the scroll positions after sorting - WidgetsBinding.instance.addPostFrameCallback((_) { - if (_horizontalScrollController.hasClients) { - _horizontalScrollController.jumpTo(horizontalScrollPosition); - } - if (_verticalScrollController.hasClients) { - _verticalScrollController.jumpTo(verticalScrollPosition); - } - }); } TableCell _buildHeader(String column) { diff --git a/pubspec.yaml b/pubspec.yaml index 9cdb05b..c8648c8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 0.7.3+32 +version: 0.7.4+33 environment: sdk: '>=3.4.3 <4.0.0'