Search packages, repositories and app categories

GitHub repositoryrodydavis/undo

undo

Undo/Redo for Flutter and Dart

undo project cover
Stars
63
Forks
14
Last push (UTC)
Jan 16, 2026
Project status
Archived

Original README

English project snapshot. Visit GitHub for the latest content.

undo

Buy Me A Coffee Donate github pages tests GitHub stars 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);
        },
      ),
    );
  }
}

Rody Davis GitHub avatar
GitHub author

Rody Davis ↗

Senior Developer Relations Engineer @google @google-deepmind supporting @google-antigravity

@GoogleSan Francisco, CAOfficial website ↗
LanguagesC++DartCMakeSwiftCHTMLKotlinObjective-C

Dependencies used

Dependency list 1 items

  • testDevelopment^1.24.9

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗