@@ -30,11 +30,10 @@ class VideoWidget extends StatefulWidget {
3030}
3131
3232class _VideoWidgetState extends State <VideoWidget > {
33- ChewieController ? chewieController ;
34- VideoPlayerController ? videoController ;
33+ ChewieController ? _chewieController ;
34+ VideoPlayerController ? _videoController ;
3535 double ? _width;
3636 double ? _height;
37- late final List <String ?> sources;
3837
3938 @override
4039 void initState () {
@@ -44,12 +43,14 @@ class _VideoWidgetState extends State<VideoWidget> {
4443 attributes['src' ],
4544 ...ReplacedElement .parseMediaSources (widget.context.tree.element! .children),
4645 ];
46+ final givenWidth = double .tryParse (attributes['width' ] ?? "" );
47+ final givenHeight = double .tryParse (attributes['height' ] ?? "" );
4748 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 ! ,
5354 placeholder: attributes['poster' ] != null && attributes['poster' ]! .isNotEmpty
5455 ? Image .network (attributes['poster' ]! )
5556 : Container (color: Colors .black),
@@ -59,32 +60,29 @@ class _VideoWidgetState extends State<VideoWidget> {
5960 autoInitialize: true ,
6061 aspectRatio: _width == null || _height == null ? null : _width! / _height! ,
6162 );
62- widget.callback? .call (widget.context.tree.element, chewieController ! , videoController ! );
63+ widget.callback? .call (widget.context.tree.element, _chewieController ! , _videoController ! );
6364 }
6465 super .initState ();
6566 }
6667
6768 @override
6869 void dispose () {
69- chewieController ? .dispose ();
70- videoController ? .dispose ();
70+ _chewieController ? .dispose ();
71+ _videoController ? .dispose ();
7172 super .dispose ();
7273 }
7374
7475 @override
7576 Widget build (BuildContext bContext) {
76- if (sources.isEmpty || sources.first == null ) {
77+ if (_chewieController == null ) {
7778 return Container (height: 0 , width: 0 );
7879 }
7980 final child = Container (
8081 key: widget.context.key,
8182 child: Chewie (
82- controller: chewieController ! ,
83+ controller: _chewieController ! ,
8384 ),
8485 );
85- if (_width == null || _height == null ) {
86- return child;
87- }
8886 return AspectRatio (
8987 aspectRatio: _width! / _height! ,
9088 child: child,
0 commit comments