transaction.dart 915 B

123456789101112131415161718192021222324252627282930
  1. import 'dart:collection';
  2. import 'package:flutter/material.dart';
  3. import 'package:flowy_editor/document/selection.dart';
  4. import './operation.dart';
  5. /// This class to use to store the **changes**
  6. /// will be applied to the editor.
  7. ///
  8. /// This class is immutable version the the class
  9. /// [[Transaction]]. Is used to stored and
  10. /// transmit. If you want to build the transaction,
  11. /// use [[Transaction]] directly.
  12. ///
  13. /// There will be several ways to consume the transaction:
  14. /// 1. Apply to the state to update the UI.
  15. /// 2. Send to the backend to store and do operation transforming.
  16. /// 3. Stored by the UndoManager to implement redo/undo.
  17. ///
  18. @immutable
  19. class Transaction {
  20. final UnmodifiableListView<Operation> operations;
  21. final Selection? beforeSelection;
  22. final Selection? afterSelection;
  23. const Transaction({
  24. required this.operations,
  25. this.beforeSelection,
  26. this.afterSelection,
  27. });
  28. }