撤销
适用于 Flutter 和 Dart 的撤销/重做
- 星标
- 63
- 复刻
- 14
- 最近推送(UTC)
- 2026年1月16日
- 项目状态
- 已归档
原始 README
以下为英文项目原文快照,最新内容请访问 GitHub。
undo
An undo redo library for Dart/Flutter. Forked from here and updated for Flutter. Demo can be viewed here.
[!WARNING] This project has moved here: https://github.com/rodydavis/packages.dart
Usage
Create an ChangeStack to store changes
import 'package:undo/undo.dart';
var changes = ChangeStack();
Add new undo, redo commands using ChangeStack.add(). When a change is added, it calls the change's execute() method. Use Change() for simple inline changes.
var count = 0;
changes.add(
Change(count, () => count++, (val) => count = val);
name: "Increase"
);
Use Change() when changing a field on an object. This will store the field's old value so it can be reverted.
var person = new Person()
..firstName = "John"
..lastName = "Doe";
changes.add(
Change(
person.firstName,
() => person.firstName = "Jane",
(oldValue) = person.firstName = oldValue
)
)
Undo a change with undo().
print(person.firstName); // Jane
changes.undo();
print(person.firstName); // John
Redo the change with redo().
changes.redo();
print(person.firstName); // Jane
Simple Stack Example
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
SimpleStack _controller;
@override
void initState() {
_controller = SimpleStack<int>(
0,
onUpdate: (val) {
if (mounted)
setState(() {
print('New Value -> $val');
});
},
);
super.initState();
}
@override
Widget build(BuildContext context) {
final count = _controller.state;
return Scaffold(
appBar: AppBar(
title: Text('Undo/Redo Example'),
),
body: Center(
child: Text('Count: $count'),
),
bottomNavigationBar: BottomAppBar(
child: Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: !_controller.canUndo
? null
: () {
if (mounted)
setState(() {
_controller.undo();
});
},
),
IconButton(
icon: Icon(Icons.arrow_forward),
onPressed: !_controller.canRedo
? null
: () {
if (mounted)
setState(() {
_controller.redo();
});
},
),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
floatingActionButton: FloatingActionButton(
heroTag: ValueKey('add_button'),
child: Icon(Icons.add),
onPressed: () {
_controller.modify(count + 1);
},
),
);
}
}
语言C++DartCMakeSwiftCHTMLKotlinObjective-C
使用的依赖
依赖清单 1 项
- test开发依赖
^1.24.9
如何选择适合项目的代码仓?
先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。
- 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
- 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
- 使用前在 GitHub 核对 README、许可证与 Issues。
来源与维护
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗