adding packages

This commit is contained in:
2026-01-15 14:38:46 -08:00
parent ef86e3ab6a
commit 6869cf47e5
5253 changed files with 726695 additions and 34 deletions
+43
View File
@@ -0,0 +1,43 @@
import 'package:undo/undo.dart';
class SimpleStack<T> extends ChangeStack {
/// Simple stack for keeping track of changes and easy callback for new state changes
SimpleStack(
this._state, {
int? limit,
this.onUpdate,
}) : super(limit: limit) {
if (onUpdate != null) {
onUpdate!(_state);
}
}
late T _state;
/// Current state
T get state => _state;
set state(T val) => modify(val);
void Function(T val)? onUpdate;
void modify(T val) {
try {
add(Change<T>(
_state,
() => _newValue(val),
_newValue,
));
} catch (e) {
rethrow;
}
}
void _newValue(T val) {
_state = val;
if (onUpdate != null) {
onUpdate!(val);
}
}
}