Moved onVideoInit to class parameter on embed builder (#934)

pull/936/head
Jon Salmon 3 years ago committed by GitHub
parent ffdefaeccf
commit a4e9757a9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 13
      README.md
  3. 52
      example/lib/pages/home_page.dart
  4. 2
      example/lib/pages/read_only_page.dart
  5. 10
      example/lib/universal_ui/universal_ui.dart
  6. 2
      flutter_quill_extensions/README.md
  7. 25
      flutter_quill_extensions/lib/embeds/builders.dart
  8. 6
      flutter_quill_extensions/lib/flutter_quill_extensions.dart
  9. 1
      lib/src/widgets/delegate.dart
  10. 4
      lib/src/widgets/editor.dart
  11. 1
      lib/src/widgets/embeds.dart
  12. 2
      lib/src/widgets/text_line.dart

@ -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(

@ -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<State<StatefulWidget>> videoContainerKey)?
onVideoInit) {
BuildContext context,
QuillController controller,
Embed node,
bool readOnly,
) {
final notes = NotesBlockEmbed(node.value.data).document;
return Material(

@ -121,7 +121,7 @@ class _HomePageState extends State<HomePage> {
sizeSmall: const TextStyle(fontSize: 9),
),
embedBuilders: [
...FlutterQuillEmbeds.builders,
...FlutterQuillEmbeds.builders(),
NotesEmbedBuilder(addEditNote: _addEditNote)
],
);
@ -287,27 +287,24 @@ class _HomePageState extends State<HomePage> {
Future<MediaPickSetting?> _selectCameraPickSetting(BuildContext context) =>
showDialog<MediaPickSetting>(
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<State<StatefulWidget>> 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));
}
}

@ -39,7 +39,7 @@ class _ReadOnlyPageState extends State<ReadOnlyPage> {
readOnly: !_edit,
expands: false,
padding: EdgeInsets.zero,
embedBuilders: FlutterQuillEmbeds.builders,
embedBuilders: FlutterQuillEmbeds.builders(),
);
if (kIsWeb) {
quillEditor = QuillEditor(

@ -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);

@ -10,7 +10,7 @@ values provided by this repository.
```
QuillEditor.basic(
controller: controller,
embedBuilders: FlutterQuillEmbeds.builders,
embedBuilders: FlutterQuillEmbeds.builders(),
);
```

@ -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();

@ -19,9 +19,11 @@ export 'embeds/toolbar/video_button.dart';
export 'embeds/utils.dart';
class FlutterQuillEmbeds {
static List<EmbedBuilder> get builders => [
static List<EmbedBuilder> builders(
{void Function(GlobalKey videoContainerKey)? onVideoInit}) =>
[
ImageEmbedBuilder(),
VideoEmbedBuilder(),
VideoEmbedBuilder(onVideoInit: onVideoInit),
FormulaEmbedBuilder(),
];

@ -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);

@ -472,7 +472,6 @@ class QuillEditorState extends State<QuillEditor>
controller,
node,
readOnly,
onVideoInit,
) {
final builders = widget.embedBuilders;
@ -486,8 +485,7 @@ class QuillEditorState extends State<QuillEditor>
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);
}
}
}

@ -13,7 +13,6 @@ abstract class EmbedBuilder {
QuillController controller,
leaf.Embed node,
bool readOnly,
void Function(GlobalKey videoContainerKey)? onVideoInit,
);
}

@ -141,7 +141,6 @@ class _TextLineState extends State<TextLine> {
widget.controller,
embed,
widget.readOnly,
null,
),
);
}
@ -189,7 +188,6 @@ class _TextLineState extends State<TextLine> {
widget.controller,
child,
widget.readOnly,
null,
),
),
);

Loading…
Cancel
Save