Skip to main content

A rich text editor with flutter_quill, saved, with undo

The flutter_quill editor and toolbar you know, on a rich text that merges with other peers. Undo takes back your own edits and leaves the others' alone.

A rich text editor with flutter_quill, saved, with undoSource ↗

A flutter_quill editor and toolbar bound to a collaborative rich text. Hive keeps the page on the device, and undo takes back only your own edits, formats included.

Flutter nativeFlutter web✓ tested in CI
import 'package:crdt_lf_hive/crdt_lf_hive.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';

import 'editor_page.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

// On the web Hive uses IndexedDB and needs no path.
if (!kIsWeb) {
Hive.init((await getApplicationDocumentsDirectory()).path);
}
CRDTHive.initialize();
final backend = await CRDTHive.open();

runApp(EditorApp(backend: backend));
}

/// The app: one rich text page stored in [backend].
class EditorApp extends StatelessWidget {
/// Creates the app of the page stored in [backend].
const EditorApp({required this.backend, super.key});

/// Where the page is stored.
final CRDTStorageBackend backend;


Widget build(BuildContext context) {
return MaterialApp(
title: 'Editor',
// flutter_quill reads its texts from here, and throws without them.
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
FlutterQuillLocalizations.delegate,
],
home: EditorPage(backend: backend),
);
}
}

Key points

  • Set up the editor package as its own documentation explains (here, the localizations of flutter_quill).
  • Hide the ChangeSource of crdt_lf when an editor package has a type with the same name.
  • The page owns the editor controller and disposes it: the binder never does.
  • Pass a CRDTUndoManager that tracks crdtQuillOrigin as undoManager: undo then takes back only the edits of this editor.