Skip to content

Commit a4e9757

Browse files
authored
Moved onVideoInit to class parameter on embed builder (singerdmx#934)
1 parent ffdefae commit a4e9757

File tree

12 files changed

+59
-61
lines changed

12 files changed

+59
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
88
99
QuillEditor.basic(
1010
controller: controller,
11-
embedBuilders: FlutterQuillEmbeds.builders,
11+
embedBuilders: FlutterQuillEmbeds.builders(),
1212
);
1313
1414
QuillToolbar.basic(

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ import 'package:flutter_quill_extensions/flutter_quill_extensions.dart';
167167
168168
QuillEditor.basic(
169169
controller: controller,
170-
embedBuilders: FlutterQuillEmbeds.builders,
170+
embedBuilders: FlutterQuillEmbeds.builders(),
171171
);
172172
173173
QuillToolbar.basic(
@@ -229,12 +229,11 @@ class NotesEmbedBuilder implements EmbedBuilder {
229229
230230
@override
231231
Widget build(
232-
BuildContext context,
233-
QuillController controller,
234-
Embed node,
235-
bool readOnly,
236-
void Function(GlobalKey<State<StatefulWidget>> videoContainerKey)?
237-
onVideoInit) {
232+
BuildContext context,
233+
QuillController controller,
234+
Embed node,
235+
bool readOnly,
236+
) {
238237
final notes = NotesBlockEmbed(node.value.data).document;
239238
240239
return Material(

example/lib/pages/home_page.dart

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class _HomePageState extends State<HomePage> {
121121
sizeSmall: const TextStyle(fontSize: 9),
122122
),
123123
embedBuilders: [
124-
...FlutterQuillEmbeds.builders,
124+
...FlutterQuillEmbeds.builders(),
125125
NotesEmbedBuilder(addEditNote: _addEditNote)
126126
],
127127
);
@@ -287,27 +287,24 @@ class _HomePageState extends State<HomePage> {
287287
Future<MediaPickSetting?> _selectCameraPickSetting(BuildContext context) =>
288288
showDialog<MediaPickSetting>(
289289
context: context,
290-
builder: (ctx) =>
291-
AlertDialog(
292-
contentPadding: EdgeInsets.zero,
293-
content: Column(
294-
mainAxisSize: MainAxisSize.min,
295-
children: [
296-
TextButton.icon(
297-
icon: const Icon(Icons.camera),
298-
label: const Text('Capture a photo'),
299-
onPressed: () =>
300-
Navigator.pop(ctx, MediaPickSetting.Camera),
301-
),
302-
TextButton.icon(
303-
icon: const Icon(Icons.video_call),
304-
label: const Text('Capture a video'),
305-
onPressed: () =>
306-
Navigator.pop(ctx, MediaPickSetting.Video),
307-
)
308-
],
290+
builder: (ctx) => AlertDialog(
291+
contentPadding: EdgeInsets.zero,
292+
content: Column(
293+
mainAxisSize: MainAxisSize.min,
294+
children: [
295+
TextButton.icon(
296+
icon: const Icon(Icons.camera),
297+
label: const Text('Capture a photo'),
298+
onPressed: () => Navigator.pop(ctx, MediaPickSetting.Camera),
309299
),
310-
),
300+
TextButton.icon(
301+
icon: const Icon(Icons.video_call),
302+
label: const Text('Capture a video'),
303+
onPressed: () => Navigator.pop(ctx, MediaPickSetting.Video),
304+
)
305+
],
306+
),
307+
),
311308
);
312309

313310
Widget _buildMenuBar(BuildContext context) {
@@ -408,12 +405,11 @@ class NotesEmbedBuilder implements EmbedBuilder {
408405

409406
@override
410407
Widget build(
411-
BuildContext context,
412-
QuillController controller,
413-
Embed node,
414-
bool readOnly,
415-
void Function(GlobalKey<State<StatefulWidget>> videoContainerKey)?
416-
onVideoInit) {
408+
BuildContext context,
409+
QuillController controller,
410+
Embed node,
411+
bool readOnly,
412+
) {
417413
final notes = NotesBlockEmbed(node.value.data).document;
418414

419415
return Material(
@@ -444,4 +440,4 @@ class NotesBlockEmbed extends CustomBlockEmbed {
444440
NotesBlockEmbed(jsonEncode(document.toDelta().toJson()));
445441

446442
Document get document => Document.fromJson(jsonDecode(data));
447-
}
443+
}

example/lib/pages/read_only_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class _ReadOnlyPageState extends State<ReadOnlyPage> {
3939
readOnly: !_edit,
4040
expands: false,
4141
padding: EdgeInsets.zero,
42-
embedBuilders: FlutterQuillEmbeds.builders,
42+
embedBuilders: FlutterQuillEmbeds.builders(),
4343
);
4444
if (kIsWeb) {
4545
quillEditor = QuillEditor(

example/lib/universal_ui/universal_ui.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ class ImageEmbedBuilderWeb implements EmbedBuilder {
3232
String get key => BlockEmbed.imageType;
3333

3434
@override
35-
Widget build(BuildContext context, QuillController controller, Embed node,
36-
bool readOnly, void Function(GlobalKey videoContainerKey)? onVideoInit) {
35+
Widget build(
36+
BuildContext context,
37+
QuillController controller,
38+
Embed node,
39+
bool readOnly,
40+
) {
3741
final imageUrl = node.value.data;
3842
if (isImageBase64(imageUrl)) {
3943
// TODO: handle imageUrl of base64
@@ -66,7 +70,7 @@ class VideoEmbedBuilderWeb implements EmbedBuilder {
6670

6771
@override
6872
Widget build(BuildContext context, QuillController controller, Embed node,
69-
bool readOnly, void Function(GlobalKey videoContainerKey)? onVideoInit) {
73+
bool readOnly) {
7074
var videoUrl = node.value.data;
7175
if (videoUrl.contains('youtube.com') || videoUrl.contains('youtu.be')) {
7276
final youtubeID = YoutubePlayer.convertUrlToId(videoUrl);

flutter_quill_extensions/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ values provided by this repository.
1010
```
1111
QuillEditor.basic(
1212
controller: controller,
13-
embedBuilders: FlutterQuillEmbeds.builders,
13+
embedBuilders: FlutterQuillEmbeds.builders(),
1414
);
1515
```
1616

flutter_quill_extensions/lib/embeds/builders.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ImageEmbedBuilder implements EmbedBuilder {
2525
QuillController controller,
2626
base.Embed node,
2727
bool readOnly,
28-
void Function(GlobalKey videoContainerKey)? onVideoInit,
2928
) {
3029
assert(!kIsWeb, 'Please provide image EmbedBuilder for Web');
3130

@@ -147,16 +146,20 @@ class ImageEmbedBuilder implements EmbedBuilder {
147146
}
148147

149148
class VideoEmbedBuilder implements EmbedBuilder {
149+
VideoEmbedBuilder({this.onVideoInit});
150+
151+
final void Function(GlobalKey videoContainerKey)? onVideoInit;
152+
150153
@override
151154
String get key => BlockEmbed.videoType;
152155

153156
@override
154157
Widget build(
155-
BuildContext context,
156-
QuillController controller,
157-
base.Embed node,
158-
bool readOnly,
159-
void Function(GlobalKey videoContainerKey)? onVideoInit) {
158+
BuildContext context,
159+
QuillController controller,
160+
base.Embed node,
161+
bool readOnly,
162+
) {
160163
assert(!kIsWeb, 'Please provide video EmbedBuilder for Web');
161164

162165
final videoUrl = node.value.data;
@@ -179,11 +182,11 @@ class FormulaEmbedBuilder implements EmbedBuilder {
179182

180183
@override
181184
Widget build(
182-
BuildContext context,
183-
QuillController controller,
184-
base.Embed node,
185-
bool readOnly,
186-
void Function(GlobalKey videoContainerKey)? onVideoInit) {
185+
BuildContext context,
186+
QuillController controller,
187+
base.Embed node,
188+
bool readOnly,
189+
) {
187190
assert(!kIsWeb, 'Please provide formula EmbedBuilder for Web');
188191

189192
final mathController = MathFieldEditingController();

flutter_quill_extensions/lib/flutter_quill_extensions.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ export 'embeds/toolbar/video_button.dart';
1919
export 'embeds/utils.dart';
2020

2121
class FlutterQuillEmbeds {
22-
static List<EmbedBuilder> get builders => [
22+
static List<EmbedBuilder> builders(
23+
{void Function(GlobalKey videoContainerKey)? onVideoInit}) =>
24+
[
2325
ImageEmbedBuilder(),
24-
VideoEmbedBuilder(),
26+
VideoEmbedBuilder(onVideoInit: onVideoInit),
2527
FormulaEmbedBuilder(),
2628
];
2729

lib/src/widgets/delegate.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ typedef EmbedsBuilder = Widget Function(
1111
QuillController controller,
1212
Embed node,
1313
bool readOnly,
14-
void Function(GlobalKey videoContainerKey)? onVideoInit,
1514
);
1615

1716
typedef CustomStyleBuilder = TextStyle Function(Attribute attribute);

lib/src/widgets/editor.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ class QuillEditorState extends State<QuillEditor>
472472
controller,
473473
node,
474474
readOnly,
475-
onVideoInit,
476475
) {
477476
final builders = widget.embedBuilders;
478477

@@ -486,8 +485,7 @@ class QuillEditorState extends State<QuillEditor>
486485

487486
for (final builder in builders) {
488487
if (builder.key == _node.value.type) {
489-
return builder.build(
490-
context, controller, _node, readOnly, onVideoInit);
488+
return builder.build(context, controller, _node, readOnly);
491489
}
492490
}
493491
}

lib/src/widgets/embeds.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ abstract class EmbedBuilder {
1313
QuillController controller,
1414
leaf.Embed node,
1515
bool readOnly,
16-
void Function(GlobalKey videoContainerKey)? onVideoInit,
1716
);
1817
}
1918

lib/src/widgets/text_line.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ class _TextLineState extends State<TextLine> {
141141
widget.controller,
142142
embed,
143143
widget.readOnly,
144-
null,
145144
),
146145
);
147146
}
@@ -189,7 +188,6 @@ class _TextLineState extends State<TextLine> {
189188
widget.controller,
190189
child,
191190
widget.readOnly,
192-
null,
193191
),
194192
),
195193
);

0 commit comments

Comments
 (0)