dartlangeditorflutterflutter-appsflutter-examplesflutter-packageflutter-widgetquillquill-deltaquilljsreactquillrich-textrich-text-editorwysiwygwysiwyg-editor
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.0 KiB
79 lines
2.0 KiB
import 'package:flutter/gestures.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter_quill/flutter_quill.dart'; |
|
import 'package:url_launcher/url_launcher.dart'; |
|
import 'package:youtube_player_flutter/youtube_player_flutter.dart'; |
|
|
|
class YoutubeVideoApp extends StatefulWidget { |
|
const YoutubeVideoApp( |
|
{required this.videoUrl, required this.context, required this.readOnly}); |
|
|
|
final String videoUrl; |
|
final BuildContext context; |
|
final bool readOnly; |
|
|
|
@override |
|
_YoutubeVideoAppState createState() => _YoutubeVideoAppState(); |
|
} |
|
|
|
class _YoutubeVideoAppState extends State<YoutubeVideoApp> { |
|
var _youtubeController; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
final videoId = YoutubePlayer.convertUrlToId(widget.videoUrl); |
|
if (videoId != null) { |
|
_youtubeController = YoutubePlayerController( |
|
initialVideoId: videoId, |
|
flags: const YoutubePlayerFlags( |
|
autoPlay: false, |
|
), |
|
); |
|
} |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
final defaultStyles = DefaultStyles.getInstance(context); |
|
if (_youtubeController == null) { |
|
if (widget.readOnly) { |
|
return RichText( |
|
text: TextSpan( |
|
text: widget.videoUrl, |
|
style: defaultStyles.link, |
|
recognizer: TapGestureRecognizer() |
|
..onTap = () => launchUrl(Uri.parse(widget.videoUrl))), |
|
); |
|
} |
|
|
|
return RichText( |
|
text: TextSpan(text: widget.videoUrl, style: defaultStyles.link)); |
|
} |
|
|
|
return Container( |
|
height: 300, |
|
child: YoutubePlayerBuilder( |
|
player: YoutubePlayer( |
|
controller: _youtubeController, |
|
showVideoProgressIndicator: true, |
|
), |
|
builder: (context, player) { |
|
return Column( |
|
children: [ |
|
// some widgets |
|
player, |
|
//some other widgets |
|
], |
|
); |
|
}, |
|
), |
|
); |
|
} |
|
|
|
@override |
|
void dispose() { |
|
super.dispose(); |
|
_youtubeController.dispose(); |
|
} |
|
}
|
|
|