From 9fde0daa1543b7fd69128e2411178237e5a237fb Mon Sep 17 00:00:00 2001 From: "k.akmalova" Date: Tue, 19 Nov 2024 23:04:02 +0300 Subject: [PATCH 1/5] fix: fixed closing when options are opened --- example/lib/app/app.dart | 300 +++++++++--------- .../widgets/cupertino_options_dialog.dart | 2 +- lib/src/material/material_controls.dart | 2 +- .../material/material_desktop_controls.dart | 2 +- lib/src/material/widgets/options_dialog.dart | 2 +- lib/src/models/option_item.dart | 4 +- 6 files changed, 156 insertions(+), 156 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index 768b4e86d..a51389400 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -158,7 +158,7 @@ class _ChewieDemoState extends State { int currPlayIndex = 0; - Future toggleVideo() async { + Future toggleVideo(BuildContext context) async { await _videoPlayerController1.pause(); currPlayIndex += 1; if (currPlayIndex >= srcs.length) { @@ -175,157 +175,157 @@ class _ChewieDemoState extends State { platform: _platform ?? Theme.of(context).platform, ), home: Scaffold( - appBar: AppBar( - title: Text(widget.title), - ), - body: Column( - children: [ - Expanded( - child: Center( - child: _chewieController != null && - _chewieController! - .videoPlayerController.value.isInitialized - ? Chewie( - controller: _chewieController!, - ) - : const Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CircularProgressIndicator(), - SizedBox(height: 20), - Text('Loading'), - ], - ), - ), - ), - TextButton( - onPressed: () { - _chewieController?.enterFullScreen(); - }, - child: const Text('Fullscreen'), - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _videoPlayerController1.pause(); - _videoPlayerController1.seekTo(Duration.zero); - _createChewieController(); - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("Landscape Video"), - ), - ), - ), - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _videoPlayerController2.pause(); - _videoPlayerController2.seekTo(Duration.zero); - _chewieController = _chewieController!.copyWith( - videoPlayerController: _videoPlayerController2, - autoPlay: true, - looping: true, - /* subtitle: Subtitles([ - Subtitle( - index: 0, - start: Duration.zero, - end: const Duration(seconds: 10), - text: 'Hello from subtitles', - ), - Subtitle( - index: 0, - start: const Duration(seconds: 10), - end: const Duration(seconds: 20), - text: 'Whats up? :)', - ), - ]), - subtitleBuilder: (context, subtitle) => Container( - padding: const EdgeInsets.all(10.0), - child: Text( - subtitle, - style: const TextStyle(color: Colors.white), - ), - ), */ - ); - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("Portrait Video"), - ), - ), - ) - ], - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _platform = TargetPlatform.android; - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("Android controls"), - ), - ), - ), - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _platform = TargetPlatform.iOS; - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("iOS controls"), - ), - ), - ) - ], - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _platform = TargetPlatform.windows; - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("Desktop controls"), - ), - ), - ), - ], - ), - if (Platform.isAndroid) - ListTile( - title: const Text("Delay"), - subtitle: DelaySlider( + appBar: AppBar( + title: Text(widget.title), + ), + body: Column( + children: [ + Expanded( + child: Center( + child: _chewieController != null && + _chewieController! + .videoPlayerController.value.isInitialized + ? Chewie( + controller: _chewieController!, + ) + : const Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CircularProgressIndicator(), + SizedBox(height: 20), + Text('Loading'), + ], + ), + ), + ), + TextButton( + onPressed: () { + _chewieController?.enterFullScreen(); + }, + child: const Text('Fullscreen'), + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _videoPlayerController1.pause(); + _videoPlayerController1.seekTo(Duration.zero); + _createChewieController(); + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("Landscape Video"), + ), + ), + ), + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _videoPlayerController2.pause(); + _videoPlayerController2.seekTo(Duration.zero); + _chewieController = _chewieController!.copyWith( + videoPlayerController: _videoPlayerController2, + autoPlay: true, + looping: true, + /* subtitle: Subtitles([ + Subtitle( + index: 0, + start: Duration.zero, + end: const Duration(seconds: 10), + text: 'Hello from subtitles', + ), + Subtitle( + index: 0, + start: const Duration(seconds: 10), + end: const Duration(seconds: 20), + text: 'Whats up? :)', + ), + ]), + subtitleBuilder: (context, subtitle) => Container( + padding: const EdgeInsets.all(10.0), + child: Text( + subtitle, + style: const TextStyle(color: Colors.white), + ), + ), */ + ); + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("Portrait Video"), + ), + ), + ) + ], + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _platform = TargetPlatform.android; + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("Android controls"), + ), + ), + ), + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _platform = TargetPlatform.iOS; + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("iOS controls"), + ), + ), + ) + ], + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _platform = TargetPlatform.windows; + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("Desktop controls"), + ), + ), + ), + ], + ), + if (Platform.isAndroid) + ListTile( + title: const Text("Delay"), + subtitle: DelaySlider( delay: _chewieController?.progressIndicatorDelay?.inMilliseconds, - onSave: (delay) async { - if (delay != null) { - bufferDelay = delay == 0 ? null : delay; - await initializePlayer(); - } - }, - ), - ) - ], - ), + onSave: (delay) async { + if (delay != null) { + bufferDelay = delay == 0 ? null : delay; + await initializePlayer(); + } + }, + ), + ) + ], + ), ), ); } diff --git a/lib/src/cupertino/widgets/cupertino_options_dialog.dart b/lib/src/cupertino/widgets/cupertino_options_dialog.dart index 1fa07aa52..9d6232436 100644 --- a/lib/src/cupertino/widgets/cupertino_options_dialog.dart +++ b/lib/src/cupertino/widgets/cupertino_options_dialog.dart @@ -24,7 +24,7 @@ class _CupertinoOptionsDialogState extends State { actions: widget.options .map( (option) => CupertinoActionSheetAction( - onPressed: () => option.onTap!(), + onPressed: () => option.onTap!(context), child: Text(option.title), ), ) diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 9b20f0722..9cd865c64 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -164,7 +164,7 @@ class _MaterialControlsState extends State Widget _buildOptionsButton() { final options = [ OptionItem( - onTap: () async { + onTap: (context) async { Navigator.pop(context); _onSpeedButtonTap(); }, diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 1b8fba8e2..e693a4b23 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -155,7 +155,7 @@ class _MaterialDesktopControlsState extends State }) { final options = [ OptionItem( - onTap: () async { + onTap: (context) async { Navigator.pop(context); _onSpeedButtonTap(); }, diff --git a/lib/src/material/widgets/options_dialog.dart b/lib/src/material/widgets/options_dialog.dart index 41a206319..2bc7f198f 100644 --- a/lib/src/material/widgets/options_dialog.dart +++ b/lib/src/material/widgets/options_dialog.dart @@ -28,7 +28,7 @@ class _OptionsDialogState extends State { itemCount: widget.options.length, itemBuilder: (context, i) { return ListTile( - onTap: widget.options[i].onTap, + onTap: () => widget.options[i].onTap?.call(context), leading: Icon(widget.options[i].iconData), title: Text(widget.options[i].title), subtitle: widget.options[i].subtitle != null diff --git a/lib/src/models/option_item.dart b/lib/src/models/option_item.dart index 403e5f720..561bc49f2 100644 --- a/lib/src/models/option_item.dart +++ b/lib/src/models/option_item.dart @@ -8,13 +8,13 @@ class OptionItem { this.subtitle, }); - Function()? onTap; + Function(BuildContext context)? onTap; IconData iconData; String title; String? subtitle; OptionItem copyWith({ - Function()? onTap, + Function(BuildContext context)? onTap, IconData? iconData, String? title, String? subtitle, From de3e76b3afd5e71fbfc67b0453c44c26956812f1 Mon Sep 17 00:00:00 2001 From: "k.akmalova" Date: Tue, 19 Nov 2024 23:23:09 +0300 Subject: [PATCH 2/5] fix: added _buildOptions --- lib/src/material/material_controls.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 9cd865c64..be62c47ff 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -161,7 +161,7 @@ class _MaterialControlsState extends State ); } - Widget _buildOptionsButton() { + List _buildOptions(BuildContext context) { final options = [ OptionItem( onTap: (context) async { @@ -178,7 +178,10 @@ class _MaterialControlsState extends State chewieController.additionalOptions!(context).isNotEmpty) { options.addAll(chewieController.additionalOptions!(context)); } + return options; + } + Widget _buildOptionsButton() { return AnimatedOpacity( opacity: notifier.hideStuff ? 0.0 : 1.0, duration: const Duration(milliseconds: 250), @@ -187,14 +190,14 @@ class _MaterialControlsState extends State _hideTimer?.cancel(); if (chewieController.optionsBuilder != null) { - await chewieController.optionsBuilder!(context, options); + await chewieController.optionsBuilder!(context, _buildOptions(context)); } else { await showModalBottomSheet( context: context, isScrollControlled: true, useRootNavigator: chewieController.useRootNavigator, builder: (context) => OptionsDialog( - options: options, + options: _buildOptions(context), cancelButtonText: chewieController.optionsTranslation?.cancelButtonText, ), From ac179709b8948f55668546c1b4a6e7f3ed76f830 Mon Sep 17 00:00:00 2001 From: "k.akmalova" Date: Tue, 19 Nov 2024 23:35:56 +0300 Subject: [PATCH 3/5] refactor: refactored --- example/lib/app/app.dart | 298 +++++++++++++++++++-------------------- 1 file changed, 149 insertions(+), 149 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index a51389400..eea1efa03 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -175,157 +175,157 @@ class _ChewieDemoState extends State { platform: _platform ?? Theme.of(context).platform, ), home: Scaffold( - appBar: AppBar( - title: Text(widget.title), - ), - body: Column( - children: [ - Expanded( - child: Center( - child: _chewieController != null && - _chewieController! - .videoPlayerController.value.isInitialized - ? Chewie( - controller: _chewieController!, - ) - : const Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CircularProgressIndicator(), - SizedBox(height: 20), - Text('Loading'), - ], - ), - ), - ), - TextButton( - onPressed: () { - _chewieController?.enterFullScreen(); - }, - child: const Text('Fullscreen'), - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _videoPlayerController1.pause(); - _videoPlayerController1.seekTo(Duration.zero); - _createChewieController(); - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("Landscape Video"), - ), - ), - ), - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _videoPlayerController2.pause(); - _videoPlayerController2.seekTo(Duration.zero); - _chewieController = _chewieController!.copyWith( - videoPlayerController: _videoPlayerController2, - autoPlay: true, - looping: true, - /* subtitle: Subtitles([ - Subtitle( - index: 0, - start: Duration.zero, - end: const Duration(seconds: 10), - text: 'Hello from subtitles', - ), - Subtitle( - index: 0, - start: const Duration(seconds: 10), - end: const Duration(seconds: 20), - text: 'Whats up? :)', - ), - ]), - subtitleBuilder: (context, subtitle) => Container( - padding: const EdgeInsets.all(10.0), - child: Text( - subtitle, - style: const TextStyle(color: Colors.white), - ), - ), */ - ); - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("Portrait Video"), - ), - ), - ) - ], - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _platform = TargetPlatform.android; - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("Android controls"), - ), - ), - ), - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _platform = TargetPlatform.iOS; - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("iOS controls"), - ), - ), - ) - ], - ), - Row( - children: [ - Expanded( - child: TextButton( - onPressed: () { - setState(() { - _platform = TargetPlatform.windows; - }); - }, - child: const Padding( - padding: EdgeInsets.symmetric(vertical: 16.0), - child: Text("Desktop controls"), - ), - ), - ), - ], - ), - if (Platform.isAndroid) - ListTile( - title: const Text("Delay"), - subtitle: DelaySlider( + appBar: AppBar( + title: Text(widget.title), + ), + body: Column( + children: [ + Expanded( + child: Center( + child: _chewieController != null && + _chewieController! + .videoPlayerController.value.isInitialized + ? Chewie( + controller: _chewieController!, + ) + : const Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CircularProgressIndicator(), + SizedBox(height: 20), + Text('Loading'), + ], + ), + ), + ), + TextButton( + onPressed: () { + _chewieController?.enterFullScreen(); + }, + child: const Text('Fullscreen'), + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _videoPlayerController1.pause(); + _videoPlayerController1.seekTo(Duration.zero); + _createChewieController(); + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("Landscape Video"), + ), + ), + ), + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _videoPlayerController2.pause(); + _videoPlayerController2.seekTo(Duration.zero); + _chewieController = _chewieController!.copyWith( + videoPlayerController: _videoPlayerController2, + autoPlay: true, + looping: true, + /* subtitle: Subtitles([ + Subtitle( + index: 0, + start: Duration.zero, + end: const Duration(seconds: 10), + text: 'Hello from subtitles', + ), + Subtitle( + index: 0, + start: const Duration(seconds: 10), + end: const Duration(seconds: 20), + text: 'Whats up? :)', + ), + ]), + subtitleBuilder: (context, subtitle) => Container( + padding: const EdgeInsets.all(10.0), + child: Text( + subtitle, + style: const TextStyle(color: Colors.white), + ), + ), */ + ); + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("Portrait Video"), + ), + ), + ) + ], + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _platform = TargetPlatform.android; + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("Android controls"), + ), + ), + ), + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _platform = TargetPlatform.iOS; + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("iOS controls"), + ), + ), + ) + ], + ), + Row( + children: [ + Expanded( + child: TextButton( + onPressed: () { + setState(() { + _platform = TargetPlatform.windows; + }); + }, + child: const Padding( + padding: EdgeInsets.symmetric(vertical: 16.0), + child: Text("Desktop controls"), + ), + ), + ), + ], + ), + if (Platform.isAndroid) + ListTile( + title: const Text("Delay"), + subtitle: DelaySlider( delay: _chewieController?.progressIndicatorDelay?.inMilliseconds, - onSave: (delay) async { - if (delay != null) { - bufferDelay = delay == 0 ? null : delay; - await initializePlayer(); - } - }, - ), - ) - ], - ), + onSave: (delay) async { + if (delay != null) { + bufferDelay = delay == 0 ? null : delay; + await initializePlayer(); + } + }, + ), + ) + ], + ), ), ); } From fcfa7a048bd86527beef26c9096cec466ef20dfa Mon Sep 17 00:00:00 2001 From: "k.akmalova" Date: Thu, 9 Jan 2025 19:41:24 +0300 Subject: [PATCH 4/5] refactor: removed unused parameter --- example/lib/app/app.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/lib/app/app.dart b/example/lib/app/app.dart index eea1efa03..bb52f2bb5 100644 --- a/example/lib/app/app.dart +++ b/example/lib/app/app.dart @@ -119,7 +119,7 @@ class _ChewieDemoState extends State { additionalOptions: (context) { return [ OptionItem( - onTap: toggleVideo, + onTap: (context) => toggleVideo(), iconData: Icons.live_tv_sharp, title: 'Toggle Video Src', ), @@ -158,7 +158,7 @@ class _ChewieDemoState extends State { int currPlayIndex = 0; - Future toggleVideo(BuildContext context) async { + Future toggleVideo() async { await _videoPlayerController1.pause(); currPlayIndex += 1; if (currPlayIndex >= srcs.length) { From 4238c69592d5b53d8dfd251136497c4f7b8fa175 Mon Sep 17 00:00:00 2001 From: "k.akmalova" Date: Thu, 16 Jan 2025 19:21:58 +0300 Subject: [PATCH 5/5] refactor: fixed formatting and made onTap not null --- lib/src/cupertino/widgets/cupertino_options_dialog.dart | 2 +- lib/src/material/material_controls.dart | 3 ++- lib/src/material/widgets/options_dialog.dart | 2 +- lib/src/models/option_item.dart | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/src/cupertino/widgets/cupertino_options_dialog.dart b/lib/src/cupertino/widgets/cupertino_options_dialog.dart index 9d6232436..4b923dc6e 100644 --- a/lib/src/cupertino/widgets/cupertino_options_dialog.dart +++ b/lib/src/cupertino/widgets/cupertino_options_dialog.dart @@ -24,7 +24,7 @@ class _CupertinoOptionsDialogState extends State { actions: widget.options .map( (option) => CupertinoActionSheetAction( - onPressed: () => option.onTap!(context), + onPressed: () => option.onTap(context), child: Text(option.title), ), ) diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index be62c47ff..38915d55a 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -190,7 +190,8 @@ class _MaterialControlsState extends State _hideTimer?.cancel(); if (chewieController.optionsBuilder != null) { - await chewieController.optionsBuilder!(context, _buildOptions(context)); + await chewieController.optionsBuilder!( + context, _buildOptions(context)); } else { await showModalBottomSheet( context: context, diff --git a/lib/src/material/widgets/options_dialog.dart b/lib/src/material/widgets/options_dialog.dart index 2bc7f198f..047f12097 100644 --- a/lib/src/material/widgets/options_dialog.dart +++ b/lib/src/material/widgets/options_dialog.dart @@ -28,7 +28,7 @@ class _OptionsDialogState extends State { itemCount: widget.options.length, itemBuilder: (context, i) { return ListTile( - onTap: () => widget.options[i].onTap?.call(context), + onTap: () => widget.options[i].onTap(context), leading: Icon(widget.options[i].iconData), title: Text(widget.options[i].title), subtitle: widget.options[i].subtitle != null diff --git a/lib/src/models/option_item.dart b/lib/src/models/option_item.dart index 561bc49f2..089d34294 100644 --- a/lib/src/models/option_item.dart +++ b/lib/src/models/option_item.dart @@ -8,10 +8,10 @@ class OptionItem { this.subtitle, }); - Function(BuildContext context)? onTap; - IconData iconData; - String title; - String? subtitle; + final void Function(BuildContext context) onTap; + final IconData iconData; + final String title; + final String? subtitle; OptionItem copyWith({ Function(BuildContext context)? onTap,