Server detail page cards support sorting

This commit is contained in:
lollipopkit
2023-05-26 18:03:43 +08:00
parent 20ef9d4575
commit 00fdcb1ee8
7 changed files with 128 additions and 71 deletions

View File

@@ -0,0 +1,22 @@
import 'package:toolbox/core/persistant_store.dart';
typedef StringOrder = List<String>;
extension StringOrderX on StringOrder {
void move(int oldIndex, int newIndex, StoreProperty property) {
if (oldIndex == newIndex) return;
if (oldIndex < newIndex) {
newIndex -= 1;
}
final item = this[oldIndex];
removeAt(oldIndex);
insert(newIndex, item);
property.put(this);
}
void update(String id, String newId) {
final index = indexOf(id);
if (index == -1) return;
this[index] = newId;
}
}