mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
Server detail page cards support sorting
This commit is contained in:
22
lib/core/extension/order.dart
Normal file
22
lib/core/extension/order.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user