class ControllerWidget extends InheritedWidget {
ControllerWidget({
this.controlKey,
this.child,
this.controller,
this.videoInit,
this.title
});
final String title;
final GlobalKey controlKey;
final Widget child;
final VideoPlayerController controller;
final bool videoInit;
//定义一个便捷方法,方便子树中的widget获取共享数据
static ControllerWidget of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType();
}
@override
bool updateShouldNotify(InheritedWidget oldWidget) {
// TODO: implement updateShouldNotify
return false;
}
}
这里面VideoPlayerController
这个controller我们后面会经常使用,用于调用操作视频相关api。
4. 入口控件VideoPlayerUI
4.1. 定义属性
这里定义了三种读取视频的方式network
、asset
、file
,分别对应网络视频
、工程视频
、本地视频文件
:
class VideoPlayerUI extends StatefulWidget {
VideoPlayerUI.network({
Key key,
@required String url, // 当前需要播放的地址
this.width: double.infinity, // 播放器尺寸(大于等于视频播放区域)
this.height: double.infinity,
this.title = ‘’, // 视频需要显示的标题
}) : type = VideoPlayerType.network,
url = url,
super(key: key);
VideoPlayerUI.asset({
Key key,
@required String dataSource, // 当前需要播放的地址
this.width: double.infinity, // 播放器尺寸(大于等于视频播放区