Skip to content

Commit

Permalink
Fixed sorting bug in table tab (#280)
Browse files Browse the repository at this point in the history
* Fixed sorting bug in table tab

* Bump v0.7.4+33
  • Loading branch information
andreped authored Sep 22, 2024
1 parent 335878f commit 147f6df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
30 changes: 4 additions & 26 deletions lib/widgets/table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,6 @@ class _TableWidgetState extends State<TableWidget> {
}

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;
Expand All @@ -237,25 +225,15 @@ class _TableWidgetState extends State<TableWidget> {
// 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) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 147f6df

Please sign in to comment.