@@ -6,16 +6,24 @@ import 'package:flutter_html/flutter_html.dart';
66import 'package:video_player/video_player.dart' ;
77import 'package:html/dom.dart' as dom;
88
9- typedef AudioControllerCallback = void Function (dom.Element ? , ChewieAudioController , VideoPlayerController );
9+ typedef AudioControllerCallback = void Function (
10+ dom.Element ? , ChewieAudioController , VideoPlayerController );
1011
11- CustomRender audioRender ({AudioControllerCallback ? onControllerCreated})
12- => CustomRender .widget (widget: (context, buildChildren)
13- => AudioWidget (context: context, callback: onControllerCreated));
12+ /// The CustomRender function for the `<audio>` tag
13+ CustomRender audioRender ({AudioControllerCallback ? onControllerCreated}) =>
14+ CustomRender .widget (
15+ widget: (context, buildChildren) => AudioWidget (
16+ context: context,
17+ callback: onControllerCreated,
18+ ),
19+ );
1420
21+ /// The CustomRenderMatcher that will match the `<audio>` tag
1522CustomRenderMatcher audioMatcher () => (context) {
16- return context.tree.element? .localName == "audio" ;
17- };
23+ return context.tree.element? .localName == "audio" ;
24+ };
1825
26+ /// A widget used for rendering an audio player in the HTML tree
1927class AudioWidget extends StatefulWidget {
2028 final RenderContext context;
2129 final AudioControllerCallback ? callback;
@@ -39,7 +47,8 @@ class _AudioWidgetState extends State<AudioWidget> {
3947 sources = < String ? > [
4048 if (widget.context.tree.element? .attributes['src' ] != null )
4149 widget.context.tree.element! .attributes['src' ],
42- ...ReplacedElement .parseMediaSources (widget.context.tree.element! .children),
50+ ...ReplacedElement .parseMediaSources (
51+ widget.context.tree.element! .children),
4352 ];
4453 if (sources.isNotEmpty && sources.first != null ) {
4554 audioController = VideoPlayerController .network (
@@ -49,10 +58,12 @@ class _AudioWidgetState extends State<AudioWidget> {
4958 videoPlayerController: audioController! ,
5059 autoPlay: widget.context.tree.element? .attributes['autoplay' ] != null ,
5160 looping: widget.context.tree.element? .attributes['loop' ] != null ,
52- showControls: widget.context.tree.element? .attributes['controls' ] != null ,
61+ showControls:
62+ widget.context.tree.element? .attributes['controls' ] != null ,
5363 autoInitialize: true ,
5464 );
55- widget.callback? .call (widget.context.tree.element, chewieAudioController! , audioController! );
65+ widget.callback? .call (widget.context.tree.element, chewieAudioController! ,
66+ audioController! );
5667 }
5768 super .initState ();
5869 }
@@ -72,11 +83,10 @@ class _AudioWidgetState extends State<AudioWidget> {
7283 return Container (
7384 key: widget.context.key,
7485 width: widget.context.style.width ?? 300 ,
75- height: Theme .of (bContext).platform == TargetPlatform .android
76- ? 48 : 75 ,
86+ height: Theme .of (bContext).platform == TargetPlatform .android ? 48 : 75 ,
7787 child: ChewieAudio (
7888 controller: chewieAudioController! ,
7989 ),
8090 );
8191 }
82- }
92+ }
0 commit comments