Unable to support youtube video

pull/298/head
Xin Yao 5 years ago
parent ac1425a1b0
commit e2c66a1c4e
  1. 2
      example/assets/sample_data.json
  2. 12
      lib/src/models/documents/document.dart
  3. 4
      lib/src/widgets/editor.dart

@ -19,7 +19,7 @@
},
{
"insert": {
"video": "https://www.youtube.com/watch?v=V4hgdKhIqtc&list=PLbhaS_83B97s78HsDTtplRTEhcFsqSqIK&index=1"
"video": "https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4"
}
},
{

@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:collection';
import 'package:tuple/tuple.dart';
@ -209,16 +210,19 @@ class Document {
static void _autoAppendNewlineAfterImage(
int i, List<Operation> ops, Operation op, Delta res) {
final nextOpIsImage =
i + 1 < ops.length && ops[i + 1].isInsert && ops[i + 1].data is! String;
final nextOpIsImage = i + 1 < ops.length &&
ops[i + 1].isInsert &&
ops[i + 1].data is Map &&
(ops[i + 1].data as Map).containsKey('image');
if (nextOpIsImage &&
op.data is String &&
(op.data as String).isNotEmpty &&
!(op.data as String).endsWith('\n')) {
res.push(Operation.insert('\n'));
}
// Currently embed is equivalent to image and hence `is! String`
final opInsertImage = op.isInsert && op.data is! String;
// embed could be image or video
final opInsertImage =
op.isInsert && op.data is Map && (op.data as Map).containsKey('image');
final nextOpIsLineBreak = i + 1 < ops.length &&
ops[i + 1].isInsert &&
ops[i + 1].data is String &&

@ -25,6 +25,7 @@ import 'delegate.dart';
import 'image.dart';
import 'raw_editor.dart';
import 'text_selection.dart';
import 'video_app.dart';
const linkPrefixes = [
'mailto:', // email
@ -105,6 +106,9 @@ Widget _defaultEmbedBuilder(BuildContext context, leaf.Embed node) {
: isBase64(imageUrl)
? Image.memory(base64.decode(imageUrl))
: Image.file(io.File(imageUrl));
case 'video':
final videoUrl = node.value.data;
return VideoApp(videoUrl: videoUrl);
default:
throw UnimplementedError(
'Embeddable type "${node.value.type}" is not supported by default '

Loading…
Cancel
Save