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.
80 lines
2.0 KiB
80 lines
2.0 KiB
4 years ago
|
import 'package:flutter/gestures.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
3 years ago
|
import 'package:flutter_quill/flutter_quill.dart';
|
||
4 years ago
|
import 'package:url_launcher/url_launcher.dart';
|
||
3 years ago
|
import 'package:youtube_player_flutter_quill/youtube_player_flutter_quill.dart';
|
||
3 years ago
|
|
||
4 years ago
|
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()
|
||
3 years ago
|
..onTap = () => launchUrl(Uri.parse(widget.videoUrl))),
|
||
4 years ago
|
);
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
}
|