optimitic update in flutter
This commit is contained in:
@@ -122,21 +122,41 @@ class _MainAppState extends State<MainApp> {
|
||||
String newGroupId,
|
||||
int newLane,
|
||||
) {
|
||||
final payload = <String, Object?>{
|
||||
final duration = entry.end.difference(entry.start);
|
||||
final newEnd = entry.hasEnd ? newStart.add(duration) : null;
|
||||
|
||||
// Optimistic update – apply locally before the host round-trips.
|
||||
if (_state case final state?) {
|
||||
final oldItem = state.items[entry.id];
|
||||
if (oldItem != null) {
|
||||
final updatedItems = Map<String, TimelineItemData>.of(state.items);
|
||||
updatedItems[entry.id] = TimelineItemData(
|
||||
id: oldItem.id,
|
||||
groupId: newGroupId,
|
||||
title: oldItem.title,
|
||||
description: oldItem.description,
|
||||
start: newStart.toIso8601String(),
|
||||
end: newEnd?.toIso8601String(),
|
||||
lane: newLane,
|
||||
);
|
||||
final updatedState = TimelineState(
|
||||
timeline: state.timeline,
|
||||
groups: state.groups,
|
||||
items: updatedItems,
|
||||
groupOrder: state.groupOrder,
|
||||
selectedItemId: state.selectedItemId,
|
||||
);
|
||||
_applyState(updatedState);
|
||||
}
|
||||
}
|
||||
|
||||
emitEvent('entry_moved', <String, Object?>{
|
||||
'entryId': entry.id,
|
||||
'newStart': newStart.toIso8601String(),
|
||||
'newGroupId': newGroupId,
|
||||
'newLane': newLane,
|
||||
};
|
||||
|
||||
if (entry.hasEnd) {
|
||||
final duration = entry.end.difference(entry.start);
|
||||
payload['newEnd'] = newStart.add(duration).toIso8601String();
|
||||
} else {
|
||||
payload['newEnd'] = null;
|
||||
}
|
||||
|
||||
emitEvent('entry_moved', payload);
|
||||
'newEnd': newEnd?.toIso8601String(),
|
||||
});
|
||||
}
|
||||
|
||||
void _emitContentHeight() {
|
||||
|
||||
Reference in New Issue
Block a user