From 3f5db3d151490bae373cda9a9ef219e3682f8dc6 Mon Sep 17 00:00:00 2001 From: X Code Date: Thu, 15 Sep 2022 12:09:12 -0700 Subject: [PATCH] Add onImagePaste in example --- example/lib/pages/home_page.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/example/lib/pages/home_page.dart b/example/lib/pages/home_page.dart index c222502d..63292458 100644 --- a/example/lib/pages/home_page.dart +++ b/example/lib/pages/home_page.dart @@ -110,6 +110,7 @@ class _HomePageState extends State { placeholder: 'Add content', expands: false, padding: EdgeInsets.zero, + onImagePaste: _onImagePaste, customStyles: DefaultStyles( h1: DefaultTextBlockStyle( const TextStyle( @@ -351,6 +352,15 @@ class _HomePageState extends State { ); } + Future _onImagePaste(Uint8List imageBytes) async { + // Copies the picked file from temporary cache to applications directory + final appDocDir = await getApplicationDocumentsDirectory(); + final file = await File( + '${appDocDir.path}/${basename('${DateTime.now().millisecondsSinceEpoch}.png')}') + .writeAsBytes(imageBytes); + return file.path.toString(); + } + Future _addEditNote(BuildContext context, {Document? document}) async { final isEditing = document != null; final quillEditorController = QuillController(