패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소rodydavis/undo

취소

Flutter 및 Dart용 되돌리기/다시하기

취소 프로젝트 이미지
스타
63
포크
14
최근 푸시(UTC)
2026. 1. 16.
프로젝트 상태
보관됨

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

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 작성자

Rody Davis ↗

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

@GoogleSan Francisco, CA공식 웹사이트 ↗
언어C++DartCMakeSwiftCHTMLKotlinObjective-C

사용 중인 의존성

의존성 목록 1 개

  • test개발 의존성^1.24.9

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

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

GitHub Docs — About repositories ↗