toggleBy method
Toggles single-field sorting between ascending and descending order.
If the current primary sort is not fieldName, sorting starts in
ascending order.
Implementation
Future<bool> toggleBy(String fieldName) {
if (!_canApplyViewOperation()) {
return Future<bool>.value(false);
}
final normalizedFieldName = FdcFieldName.normalize(fieldName);
final current = items;
final isCurrentPrimarySort =
current.isNotEmpty &&
FdcFieldName.normalize(current.first.fieldName) == normalizedFieldName;
return set(<FdcDataSetSort>[
FdcDataSetSort(
fieldName: fieldName,
sortType: isCurrentPrimarySort
? current.first.sortType.toggled
: FdcSortType.ascending,
),
]);
}