From a4e9757a9cf29d998dbecd823ff30def95ac062e Mon Sep 17 00:00:00 2001 From: Jon Salmon <26483285+Jon-Salmon@users.noreply.github.com> Date: Sun, 4 Sep 2022 23:23:08 +0100 Subject: [PATCH] Moved onVideoInit to class parameter on embed builder (#934) --- CHANGELOG.md | 2 +- README.md | 13 +++-- example/lib/pages/home_page.dart | 52 +++++++++---------- example/lib/pages/read_only_page.dart | 2 +- example/lib/universal_ui/universal_ui.dart | 10 ++-- flutter_quill_extensions/README.md | 2 +- .../lib/embeds/builders.dart | 25 +++++---- .../lib/flutter_quill_extensions.dart | 6 ++- lib/src/widgets/delegate.dart | 1 - lib/src/widgets/editor.dart | 4 +- lib/src/widgets/embeds.dart | 1 - lib/src/widgets/text_line.dart | 2 - 12 files changed, 59 insertions(+), 61 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be1006b0..f4e428a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ import 'package:flutter_quill_extensions/flutter_quill_extensions.dart'; QuillEditor.basic( controller: controller, - embedBuilders: FlutterQuillEmbeds.builders, + embedBuilders: FlutterQuillEmbeds.builders(), ); QuillToolbar.basic( diff --git a/README.md b/README.md index 962ac7d5..d2a6f41b 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ import 'package:flutter_quill_extensions/flutter_quill_extensions.dart'; QuillEditor.basic( controller: controller, - embedBuilders: FlutterQuillEmbeds.builders, + embedBuilders: FlutterQuillEmbeds.builders(), ); QuillToolbar.basic( @@ -229,12 +229,11 @@ class NotesEmbedBuilder implements EmbedBuilder { @override Widget build( - BuildContext context, - QuillController controller, - Embed node, - bool readOnly, - void Function(GlobalKey> videoContainerKey)? - onVideoInit) { + BuildContext context, + QuillController controller, + Embed node, + bool readOnly, + ) { final notes = NotesBlockEmbed(node.value.data).document; return Material( diff --git a/example/lib/pages/home_page.dart b/example/lib/pages/home_page.dart index 2d9b09b8..9910e4dd 100644 --- a/example/lib/pages/home_page.dart +++ b/example/lib/pages/home_page.dart @@ -121,7 +121,7 @@ class _HomePageState extends State { sizeSmall: const TextStyle(fontSize: 9), ), embedBuilders: [ - ...FlutterQuillEmbeds.builders, + ...FlutterQuillEmbeds.builders(), NotesEmbedBuilder(addEditNote: _addEditNote) ], ); @@ -287,27 +287,24 @@ class _HomePageState extends State { Future _selectCameraPickSetting(BuildContext context) => showDialog( context: context, - builder: (ctx) => - AlertDialog( - contentPadding: EdgeInsets.zero, - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - TextButton.icon( - icon: const Icon(Icons.camera), - label: const Text('Capture a photo'), - onPressed: () => - Navigator.pop(ctx, MediaPickSetting.Camera), - ), - TextButton.icon( - icon: const Icon(Icons.video_call), - label: const Text('Capture a video'), - onPressed: () => - Navigator.pop(ctx, MediaPickSetting.Video), - ) - ], + builder: (ctx) => AlertDialog( + contentPadding: EdgeInsets.zero, + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextButton.icon( + icon: const Icon(Icons.camera), + label: const Text('Capture a photo'), + onPressed: () => Navigator.pop(ctx, MediaPickSetting.Camera), ), - ), + TextButton.icon( + icon: const Icon(Icons.video_call), + label: const Text('Capture a video'), + onPressed: () => Navigator.pop(ctx, MediaPickSetting.Video), + ) + ], + ), + ), ); Widget _buildMenuBar(BuildContext context) { @@ -408,12 +405,11 @@ class NotesEmbedBuilder implements EmbedBuilder { @override Widget build( - BuildContext context, - QuillController controller, - Embed node, - bool readOnly, - void Function(GlobalKey> videoContainerKey)? - onVideoInit) { + BuildContext context, + QuillController controller, + Embed node, + bool readOnly, + ) { final notes = NotesBlockEmbed(node.value.data).document; return Material( @@ -444,4 +440,4 @@ class NotesBlockEmbed extends CustomBlockEmbed { NotesBlockEmbed(jsonEncode(document.toDelta().toJson())); Document get document => Document.fromJson(jsonDecode(data)); -} \ No newline at end of file +} diff --git a/example/lib/pages/read_only_page.dart b/example/lib/pages/read_only_page.dart index 478d7924..469e9f86 100644 --- a/example/lib/pages/read_only_page.dart +++ b/example/lib/pages/read_only_page.dart @@ -39,7 +39,7 @@ class _ReadOnlyPageState extends State { readOnly: !_edit, expands: false, padding: EdgeInsets.zero, - embedBuilders: FlutterQuillEmbeds.builders, + embedBuilders: FlutterQuillEmbeds.builders(), ); if (kIsWeb) { quillEditor = QuillEditor( diff --git a/example/lib/universal_ui/universal_ui.dart b/example/lib/universal_ui/universal_ui.dart index 54441820..443255a4 100644 --- a/example/lib/universal_ui/universal_ui.dart +++ b/example/lib/universal_ui/universal_ui.dart @@ -32,8 +32,12 @@ class ImageEmbedBuilderWeb implements EmbedBuilder { String get key => BlockEmbed.imageType; @override - Widget build(BuildContext context, QuillController controller, Embed node, - bool readOnly, void Function(GlobalKey videoContainerKey)? onVideoInit) { + Widget build( + BuildContext context, + QuillController controller, + Embed node, + bool readOnly, + ) { final imageUrl = node.value.data; if (isImageBase64(imageUrl)) { // TODO: handle imageUrl of base64 @@ -66,7 +70,7 @@ class VideoEmbedBuilderWeb implements EmbedBuilder { @override Widget build(BuildContext context, QuillController controller, Embed node, - bool readOnly, void Function(GlobalKey videoContainerKey)? onVideoInit) { + bool readOnly) { var videoUrl = node.value.data; if (videoUrl.contains('youtube.com') || videoUrl.contains('youtu.be')) { final youtubeID = YoutubePlayer.convertUrlToId(videoUrl); diff --git a/flutter_quill_extensions/README.md b/flutter_quill_extensions/README.md index b52b47c5..a685b8f0 100644 --- a/flutter_quill_extensions/README.md +++ b/flutter_quill_extensions/README.md @@ -10,7 +10,7 @@ values provided by this repository. ``` QuillEditor.basic( controller: controller, - embedBuilders: FlutterQuillEmbeds.builders, + embedBuilders: FlutterQuillEmbeds.builders(), ); ``` diff --git a/flutter_quill_extensions/lib/embeds/builders.dart b/flutter_quill_extensions/lib/embeds/builders.dart index 8e3540c7..c443cc59 100644 --- a/flutter_quill_extensions/lib/embeds/builders.dart +++ b/flutter_quill_extensions/lib/embeds/builders.dart @@ -25,7 +25,6 @@ class ImageEmbedBuilder implements EmbedBuilder { QuillController controller, base.Embed node, bool readOnly, - void Function(GlobalKey videoContainerKey)? onVideoInit, ) { assert(!kIsWeb, 'Please provide image EmbedBuilder for Web'); @@ -147,16 +146,20 @@ class ImageEmbedBuilder implements EmbedBuilder { } class VideoEmbedBuilder implements EmbedBuilder { + VideoEmbedBuilder({this.onVideoInit}); + + final void Function(GlobalKey videoContainerKey)? onVideoInit; + @override String get key => BlockEmbed.videoType; @override Widget build( - BuildContext context, - QuillController controller, - base.Embed node, - bool readOnly, - void Function(GlobalKey videoContainerKey)? onVideoInit) { + BuildContext context, + QuillController controller, + base.Embed node, + bool readOnly, + ) { assert(!kIsWeb, 'Please provide video EmbedBuilder for Web'); final videoUrl = node.value.data; @@ -179,11 +182,11 @@ class FormulaEmbedBuilder implements EmbedBuilder { @override Widget build( - BuildContext context, - QuillController controller, - base.Embed node, - bool readOnly, - void Function(GlobalKey videoContainerKey)? onVideoInit) { + BuildContext context, + QuillController controller, + base.Embed node, + bool readOnly, + ) { assert(!kIsWeb, 'Please provide formula EmbedBuilder for Web'); final mathController = MathFieldEditingController(); diff --git a/flutter_quill_extensions/lib/flutter_quill_extensions.dart b/flutter_quill_extensions/lib/flutter_quill_extensions.dart index e23b9d66..eefecbf0 100644 --- a/flutter_quill_extensions/lib/flutter_quill_extensions.dart +++ b/flutter_quill_extensions/lib/flutter_quill_extensions.dart @@ -19,9 +19,11 @@ export 'embeds/toolbar/video_button.dart'; export 'embeds/utils.dart'; class FlutterQuillEmbeds { - static List get builders => [ + static List builders( + {void Function(GlobalKey videoContainerKey)? onVideoInit}) => + [ ImageEmbedBuilder(), - VideoEmbedBuilder(), + VideoEmbedBuilder(onVideoInit: onVideoInit), FormulaEmbedBuilder(), ]; diff --git a/lib/src/widgets/delegate.dart b/lib/src/widgets/delegate.dart index 812277a8..f2328849 100644 --- a/lib/src/widgets/delegate.dart +++ b/lib/src/widgets/delegate.dart @@ -11,7 +11,6 @@ typedef EmbedsBuilder = Widget Function( QuillController controller, Embed node, bool readOnly, - void Function(GlobalKey videoContainerKey)? onVideoInit, ); typedef CustomStyleBuilder = TextStyle Function(Attribute attribute); diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index 1bb63641..bb673c4b 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -472,7 +472,6 @@ class QuillEditorState extends State controller, node, readOnly, - onVideoInit, ) { final builders = widget.embedBuilders; @@ -486,8 +485,7 @@ class QuillEditorState extends State for (final builder in builders) { if (builder.key == _node.value.type) { - return builder.build( - context, controller, _node, readOnly, onVideoInit); + return builder.build(context, controller, _node, readOnly); } } } diff --git a/lib/src/widgets/embeds.dart b/lib/src/widgets/embeds.dart index ffbcd14a..c0262a08 100644 --- a/lib/src/widgets/embeds.dart +++ b/lib/src/widgets/embeds.dart @@ -13,7 +13,6 @@ abstract class EmbedBuilder { QuillController controller, leaf.Embed node, bool readOnly, - void Function(GlobalKey videoContainerKey)? onVideoInit, ); } diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index 8c7d1be2..b20ea22f 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -141,7 +141,6 @@ class _TextLineState extends State { widget.controller, embed, widget.readOnly, - null, ), ); } @@ -189,7 +188,6 @@ class _TextLineState extends State { widget.controller, child, widget.readOnly, - null, ), ), );