mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
#54 snippet group
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
import 'package:toolbox/core/persistant_store.dart';
|
||||
|
||||
typedef Order<T> = List<T>;
|
||||
typedef _OnMove<T> = void Function(Order<T>);
|
||||
|
||||
extension OrderX<T> on Order<T> {
|
||||
void move(int oldIndex, int newIndex, StoreProperty<List<T>> property) {
|
||||
void move(
|
||||
int oldIndex,
|
||||
int newIndex, {
|
||||
StoreProperty<List<T>>? property,
|
||||
_OnMove<T>? onMove,
|
||||
}) {
|
||||
if (oldIndex == newIndex) return;
|
||||
if (oldIndex < newIndex) {
|
||||
newIndex -= 1;
|
||||
@@ -11,7 +17,8 @@ extension OrderX<T> on Order<T> {
|
||||
final item = this[oldIndex];
|
||||
removeAt(oldIndex);
|
||||
insert(newIndex, item);
|
||||
property.put(this);
|
||||
property?.put(this);
|
||||
onMove?.call(this);
|
||||
}
|
||||
|
||||
void update(T id, T newId) {
|
||||
@@ -24,11 +31,16 @@ extension OrderX<T> on Order<T> {
|
||||
return indexOf(id);
|
||||
}
|
||||
|
||||
void moveById(T oid, T nid, StoreProperty<List<T>> property) {
|
||||
void moveById(
|
||||
T oid,
|
||||
T nid, {
|
||||
StoreProperty<List<T>>? property,
|
||||
_OnMove<T>? onMove,
|
||||
}) {
|
||||
final index = indexOf(oid);
|
||||
if (index == -1) return;
|
||||
final newIndex = indexOf(nid);
|
||||
if (newIndex == -1) return;
|
||||
move(index, newIndex, property);
|
||||
move(index, newIndex, property: property, onMove: onMove);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user