Refactor code

pull/635/head
X Code 3 years ago
parent 45a9597f7f
commit a1f39564f6
  1. 40
      lib/src/widgets/embeds/default_embed_builder.dart

@ -43,6 +43,25 @@ Widget defaultEmbedBuilder(
} }
// We provide option menu only for mobile platform excluding base64 image // We provide option menu only for mobile platform excluding base64 image
return _menuOptionsForReadonlyImage(context, imageUrl, image);
case 'video':
final videoUrl = node.value.data;
if (videoUrl.contains('youtube.com') || videoUrl.contains('youtu.be')) {
return YoutubeVideoApp(
videoUrl: videoUrl, context: context, readOnly: readOnly);
}
return VideoApp(videoUrl: videoUrl, context: context, readOnly: readOnly);
default:
throw UnimplementedError(
'Embeddable type "${node.value.type}" is not supported by default '
'embed builder of QuillEditor. You must pass your own builder function '
'to embedBuilder property of QuillEditor or QuillField widgets.',
);
}
}
GestureDetector _menuOptionsForReadonlyImage(
BuildContext context, String imageUrl, image) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
showDialog( showDialog(
@ -51,8 +70,7 @@ Widget defaultEmbedBuilder(
padding: const EdgeInsets.fromLTRB(50, 0, 50, 0), padding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
child: SimpleDialog( child: SimpleDialog(
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: borderRadius: BorderRadius.all(Radius.circular(10))),
BorderRadius.all(Radius.circular(10))),
children: [ children: [
_SimpleDialogItem( _SimpleDialogItem(
icon: Icons.save, icon: Icons.save,
@ -73,28 +91,14 @@ Widget defaultEmbedBuilder(
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ImageTapWrapper( builder: (context) =>
imageUrl: imageUrl))); ImageTapWrapper(imageUrl: imageUrl)));
}, },
) )
]), ]),
)); ));
}, },
child: image); child: image);
case 'video':
final videoUrl = node.value.data;
if (videoUrl.contains('youtube.com') || videoUrl.contains('youtu.be')) {
return YoutubeVideoApp(
videoUrl: videoUrl, context: context, readOnly: readOnly);
}
return VideoApp(videoUrl: videoUrl, context: context, readOnly: readOnly);
default:
throw UnimplementedError(
'Embeddable type "${node.value.type}" is not supported by default '
'embed builder of QuillEditor. You must pass your own builder function '
'to embedBuilder property of QuillEditor or QuillField widgets.',
);
}
} }
class _SimpleDialogItem extends StatelessWidget { class _SimpleDialogItem extends StatelessWidget {

Loading…
Cancel
Save