import 'dart:convert'; import 'package:flutter_quill/flutter_quill.dart'; Document noteBodyToDocument(String storedBody) { final String trimmedBody = storedBody.trimLeft(); if (trimmedBody.startsWith('[')) { try { final dynamic decoded = jsonDecode(storedBody); if (decoded is List) { return Document.fromJson(decoded); } } catch (_) { // Fall back to plain text for legacy notes or malformed JSON. } } if (storedBody.isEmpty) { return Document(); } final String plainText = storedBody.endsWith('\n') ? storedBody : '$storedBody\n'; return Document.fromJson([ {'insert': plainText}, ]); } String noteBodyToPlainText(String storedBody) { return noteBodyToDocument(storedBody).toPlainText(); } String noteDocumentToStorageJson(Document document) { return jsonEncode(document.toDelta().toJson()); }