@@ -30,11 +30,10 @@ class VideoWidget extends StatefulWidget {
30
30
}
31
31
32
32
class _VideoWidgetState extends State <VideoWidget > {
33
- ChewieController ? chewieController ;
34
- VideoPlayerController ? videoController ;
33
+ ChewieController ? _chewieController ;
34
+ VideoPlayerController ? _videoController ;
35
35
double ? _width;
36
36
double ? _height;
37
- late final List <String ?> sources;
38
37
39
38
@override
40
39
void initState () {
@@ -44,12 +43,14 @@ class _VideoWidgetState extends State<VideoWidget> {
44
43
attributes['src' ],
45
44
...ReplacedElement .parseMediaSources (widget.context.tree.element! .children),
46
45
];
46
+ final givenWidth = double .tryParse (attributes['width' ] ?? "" );
47
+ final givenHeight = double .tryParse (attributes['height' ] ?? "" );
47
48
if (sources.isNotEmpty && sources.first != null ) {
48
- _width = double . tryParse (attributes[ 'width' ] ?? (attributes[ 'height' ] ?? 150 ) * 2 ) ;
49
- _height = double . tryParse (attributes[ 'height' ] ?? (attributes[ 'width' ] ?? 300 ) / 2 ) ;
50
- videoController = VideoPlayerController .network (sources.first! );
51
- chewieController = ChewieController (
52
- videoPlayerController: videoController ! ,
49
+ _width = givenWidth ?? (givenHeight ?? 150 ) * 2 ;
50
+ _height = givenHeight ?? (givenWidth ?? 300 ) / 2 ;
51
+ _videoController = VideoPlayerController .network (sources.first! );
52
+ _chewieController = ChewieController (
53
+ videoPlayerController: _videoController ! ,
53
54
placeholder: attributes['poster' ] != null && attributes['poster' ]! .isNotEmpty
54
55
? Image .network (attributes['poster' ]! )
55
56
: Container (color: Colors .black),
@@ -59,32 +60,29 @@ class _VideoWidgetState extends State<VideoWidget> {
59
60
autoInitialize: true ,
60
61
aspectRatio: _width == null || _height == null ? null : _width! / _height! ,
61
62
);
62
- widget.callback? .call (widget.context.tree.element, chewieController ! , videoController ! );
63
+ widget.callback? .call (widget.context.tree.element, _chewieController ! , _videoController ! );
63
64
}
64
65
super .initState ();
65
66
}
66
67
67
68
@override
68
69
void dispose () {
69
- chewieController ? .dispose ();
70
- videoController ? .dispose ();
70
+ _chewieController ? .dispose ();
71
+ _videoController ? .dispose ();
71
72
super .dispose ();
72
73
}
73
74
74
75
@override
75
76
Widget build (BuildContext bContext) {
76
- if (sources.isEmpty || sources.first == null ) {
77
+ if (_chewieController == null ) {
77
78
return Container (height: 0 , width: 0 );
78
79
}
79
80
final child = Container (
80
81
key: widget.context.key,
81
82
child: Chewie (
82
- controller: chewieController ! ,
83
+ controller: _chewieController ! ,
83
84
),
84
85
);
85
- if (_width == null || _height == null ) {
86
- return child;
87
- }
88
86
return AspectRatio (
89
87
aspectRatio: _width! / _height! ,
90
88
child: child,
0 commit comments