From 030cea174ce514420933aea54fa1f1f913ff36fe Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 7 Sep 2022 12:08:02 -0400 Subject: [PATCH 1/6] - Exposing MaterialDesktopControls --- lib/chewie.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/chewie.dart b/lib/chewie.dart index f26e732a6..73b73c44f 100644 --- a/lib/chewie.dart +++ b/lib/chewie.dart @@ -4,4 +4,5 @@ export 'src/chewie_player.dart'; export 'src/chewie_progress_colors.dart'; export 'src/cupertino/cupertino_controls.dart'; export 'src/material/material_controls.dart'; +export 'src/material/material_desktop_controls.dart'; export 'src/models/index.dart'; From e2c647a64e7b174a539f547d903d7d5b5e4fb52a Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 7 Sep 2022 12:10:58 -0400 Subject: [PATCH 2/6] - CenterPlayButton UI bug fixed when using Material 3 --- lib/src/center_play_button.dart | 44 +++++++++++++++++---------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/src/center_play_button.dart b/lib/src/center_play_button.dart index d9dd4543a..754d6edba 100644 --- a/lib/src/center_play_button.dart +++ b/lib/src/center_play_button.dart @@ -24,27 +24,29 @@ class CenterPlayButton extends StatelessWidget { return Container( color: Colors.transparent, child: Center( - child: AnimatedOpacity( - opacity: show ? 1.0 : 0.0, - duration: const Duration(milliseconds: 300), - child: Container( - decoration: BoxDecoration( - color: backgroundColor, - shape: BoxShape.circle, - ), - child: Padding( - padding: const EdgeInsets.all(12.0), - // Always set the iconSize on the IconButton, not on the Icon itself: - // https://github.com/flutter/flutter/issues/52980 - child: IconButton( - iconSize: 32, - icon: isFinished - ? Icon(Icons.replay, color: iconColor) - : AnimatedPlayPause( - color: iconColor, - playing: isPlaying, - ), - onPressed: onPressed, + child: UnconstrainedBox( + child: AnimatedOpacity( + opacity: show ? 1.0 : 0.0, + duration: const Duration(milliseconds: 300), + child: Container( + decoration: BoxDecoration( + color: backgroundColor, + shape: BoxShape.circle, + ), + child: Padding( + padding: const EdgeInsets.all(12.0), + // Always set the iconSize on the IconButton, not on the Icon itself: + // https://github.com/flutter/flutter/issues/52980 + child: IconButton( + iconSize: 32, + icon: isFinished + ? Icon(Icons.replay, color: iconColor) + : AnimatedPlayPause( + color: iconColor, + playing: isPlaying, + ), + onPressed: onPressed, + ), ), ), ), From 97bea9442ed671b75b14dd299a419852286f3366 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 7 Sep 2022 12:14:56 -0400 Subject: [PATCH 3/6] - Several lints fixed for better performance --- lib/src/center_play_button.dart | 4 ++-- lib/src/cupertino/cupertino_controls.dart | 10 +++++----- lib/src/helpers/adaptive_controls.dart | 1 - lib/src/material/material_controls.dart | 6 +++--- lib/src/material/material_desktop_controls.dart | 4 ++-- lib/src/player_with_controls.dart | 8 ++++---- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/src/center_play_button.dart b/lib/src/center_play_button.dart index 754d6edba..70f8f477e 100644 --- a/lib/src/center_play_button.dart +++ b/lib/src/center_play_button.dart @@ -21,14 +21,14 @@ class CenterPlayButton extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( + return ColoredBox( color: Colors.transparent, child: Center( child: UnconstrainedBox( child: AnimatedOpacity( opacity: show ? 1.0 : 0.0, duration: const Duration(milliseconds: 300), - child: Container( + child: DecoratedBox( decoration: BoxDecoration( color: backgroundColor, shape: BoxShape.circle, diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index 47de2af17..6763459e5 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -203,14 +203,14 @@ class _CupertinoControlsState extends State Widget _buildSubtitles(Subtitles subtitles) { if (!_subtitleOn) { - return Container(); + return const SizedBox(); } if (_subtitlesPosition == null) { - return Container(); + return const SizedBox(); } final currentSubtitle = subtitles.getByPosition(_subtitlesPosition!); if (currentSubtitle.isEmpty) { - return Container(); + return const SizedBox(); } if (chewieController.subtitleBuilder != null) { @@ -395,7 +395,7 @@ class _CupertinoControlsState extends State borderRadius: BorderRadius.circular(10.0), child: BackdropFilter( filter: ui.ImageFilter.blur(sigmaX: 10.0), - child: Container( + child: ColoredBox( color: backgroundColor, child: Container( height: barHeight, @@ -468,7 +468,7 @@ class _CupertinoControlsState extends State Widget _buildSubtitleToggle(Color iconColor, double barHeight) { //if don't have subtitle hiden button if (chewieController.subtitle?.isEmpty ?? true) { - return Container(); + return const SizedBox(); } return GestureDetector( onTap: _subtitleToggle, diff --git a/lib/src/helpers/adaptive_controls.dart b/lib/src/helpers/adaptive_controls.dart index 600810644..be59a7f66 100644 --- a/lib/src/helpers/adaptive_controls.dart +++ b/lib/src/helpers/adaptive_controls.dart @@ -1,5 +1,4 @@ import 'package:chewie/chewie.dart'; -import 'package:chewie/src/material/material_desktop_controls.dart'; import 'package:flutter/material.dart'; class AdaptiveControls extends StatelessWidget { diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index 8836a774e..e89e2a957 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -213,11 +213,11 @@ class _MaterialControlsState extends State Widget _buildSubtitles(BuildContext context, Subtitles subtitles) { if (!_subtitleOn) { - return Container(); + return const SizedBox(); } final currentSubtitle = subtitles.getByPosition(_subtitlesPosition); if (currentSubtitle.isEmpty) { - return Container(); + return const SizedBox(); } if (chewieController.subtitleBuilder != null) { @@ -446,7 +446,7 @@ class _MaterialControlsState extends State Widget _buildSubtitleToggle() { //if don't have subtitle hiden button if (chewieController.subtitle?.isEmpty ?? true) { - return Container(); + return const SizedBox(); } return GestureDetector( onTap: _onSubtitleTap, diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index f90326d11..2a8f15984 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -206,11 +206,11 @@ class _MaterialDesktopControlsState extends State Widget _buildSubtitles(BuildContext context, Subtitles subtitles) { if (!_subtitleOn) { - return Container(); + return const SizedBox(); } final currentSubtitle = subtitles.getByPosition(_subtitlesPosition); if (currentSubtitle.isEmpty) { - return Container(); + return const SizedBox(); } if (chewieController.subtitleBuilder != null) { diff --git a/lib/src/player_with_controls.dart b/lib/src/player_with_controls.dart index 02bb782b4..26673a64b 100644 --- a/lib/src/player_with_controls.dart +++ b/lib/src/player_with_controls.dart @@ -26,7 +26,7 @@ class PlayerWithControls extends StatelessWidget { ) { return chewieController.showControls ? chewieController.customControls ?? const AdaptiveControls() - : Container(); + : const SizedBox(); } Widget _buildPlayerWithControls( @@ -65,9 +65,9 @@ class PlayerWithControls extends StatelessWidget { duration: const Duration( milliseconds: 250, ), - child: Container( - decoration: const BoxDecoration(color: Colors.black54), - child: Container(), + child: const DecoratedBox( + decoration: BoxDecoration(color: Colors.black54), + child: SizedBox(), ), ), ), From 1c1134dd7b3c4e0785a1a9e56e6c50af6c3f336e Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 7 Sep 2022 12:15:32 -0400 Subject: [PATCH 4/6] - Example AppTheme updated to useMaterial3 --- example/lib/app/theme.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/lib/app/theme.dart b/example/lib/app/theme.dart index e0d663eda..41ac7e4d0 100644 --- a/example/lib/app/theme.dart +++ b/example/lib/app/theme.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; class AppTheme { static final light = ThemeData( brightness: Brightness.light, + useMaterial3: true, colorScheme: const ColorScheme.light(secondary: Colors.red), disabledColor: Colors.grey.shade400, visualDensity: VisualDensity.adaptivePlatformDensity, @@ -13,6 +14,7 @@ class AppTheme { brightness: Brightness.dark, colorScheme: const ColorScheme.dark(secondary: Colors.red), disabledColor: Colors.grey.shade400, + useMaterial3: true, visualDensity: VisualDensity.adaptivePlatformDensity, ); } From d0658bc69bac48149350b55a998a142fd64c7758 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 7 Sep 2022 15:12:07 -0400 Subject: [PATCH 5/6] - CenterPlayButton padding improved --- lib/src/center_play_button.dart | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/src/center_play_button.dart b/lib/src/center_play_button.dart index 70f8f477e..0f23d4f77 100644 --- a/lib/src/center_play_button.dart +++ b/lib/src/center_play_button.dart @@ -33,20 +33,18 @@ class CenterPlayButton extends StatelessWidget { color: backgroundColor, shape: BoxShape.circle, ), - child: Padding( + // Always set the iconSize on the IconButton, not on the Icon itself: + // https://github.com/flutter/flutter/issues/52980 + child: IconButton( + iconSize: 32, padding: const EdgeInsets.all(12.0), - // Always set the iconSize on the IconButton, not on the Icon itself: - // https://github.com/flutter/flutter/issues/52980 - child: IconButton( - iconSize: 32, - icon: isFinished - ? Icon(Icons.replay, color: iconColor) - : AnimatedPlayPause( - color: iconColor, - playing: isPlaying, - ), - onPressed: onPressed, - ), + icon: isFinished + ? Icon(Icons.replay, color: iconColor) + : AnimatedPlayPause( + color: iconColor, + playing: isPlaying, + ), + onPressed: onPressed, ), ), ), From 004209676c8be14b4c6258797607a4d935210cf1 Mon Sep 17 00:00:00 2001 From: Luis Date: Fri, 9 Sep 2022 13:00:52 -0400 Subject: [PATCH 6/6] - Removed leading underscores for local identifiers --- lib/src/cupertino/cupertino_controls.dart | 4 ++-- lib/src/material/material_controls.dart | 4 ++-- lib/src/material/material_desktop_controls.dart | 4 ++-- .../material/widgets/playback_speed_dialog.dart | 10 +++++----- lib/src/player_with_controls.dart | 14 +++++++------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/src/cupertino/cupertino_controls.dart b/lib/src/cupertino/cupertino_controls.dart index 6763459e5..d768db909 100644 --- a/lib/src/cupertino/cupertino_controls.dart +++ b/lib/src/cupertino/cupertino_controls.dart @@ -142,11 +142,11 @@ class _CupertinoControlsState extends State @override void didChangeDependencies() { - final _oldController = _chewieController; + final oldController = _chewieController; _chewieController = ChewieController.of(context); controller = chewieController.videoPlayerController; - if (_oldController != chewieController) { + if (oldController != chewieController) { _dispose(); _initialize(); } diff --git a/lib/src/material/material_controls.dart b/lib/src/material/material_controls.dart index e89e2a957..081f4b5cc 100644 --- a/lib/src/material/material_controls.dart +++ b/lib/src/material/material_controls.dart @@ -128,11 +128,11 @@ class _MaterialControlsState extends State @override void didChangeDependencies() { - final _oldController = _chewieController; + final oldController = _chewieController; _chewieController = ChewieController.of(context); controller = chewieController.videoPlayerController; - if (_oldController != chewieController) { + if (oldController != chewieController) { _dispose(); _initialize(); } diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 2a8f15984..7533c973b 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -128,11 +128,11 @@ class _MaterialDesktopControlsState extends State @override void didChangeDependencies() { - final _oldController = _chewieController; + final oldController = _chewieController; _chewieController = ChewieController.of(context); controller = chewieController.videoPlayerController; - if (_oldController != chewieController) { + if (oldController != chewieController) { _dispose(); _initialize(); } diff --git a/lib/src/material/widgets/playback_speed_dialog.dart b/lib/src/material/widgets/playback_speed_dialog.dart index 6164a31ea..84ff79f73 100644 --- a/lib/src/material/widgets/playback_speed_dialog.dart +++ b/lib/src/material/widgets/playback_speed_dialog.dart @@ -20,12 +20,12 @@ class PlaybackSpeedDialog extends StatelessWidget { shrinkWrap: true, physics: const ScrollPhysics(), itemBuilder: (context, index) { - final _speed = _speeds[index]; + final speed = _speeds[index]; return ListTile( dense: true, title: Row( children: [ - if (_speed == _selected) + if (speed == _selected) Icon( Icons.check, size: 20.0, @@ -34,12 +34,12 @@ class PlaybackSpeedDialog extends StatelessWidget { else Container(width: 20.0), const SizedBox(width: 16.0), - Text(_speed.toString()), + Text(speed.toString()), ], ), - selected: _speed == _selected, + selected: speed == _selected, onTap: () { - Navigator.of(context).pop(_speed); + Navigator.of(context).pop(speed); }, ); }, diff --git a/lib/src/player_with_controls.dart b/lib/src/player_with_controls.dart index 26673a64b..75b3525ed 100644 --- a/lib/src/player_with_controls.dart +++ b/lib/src/player_with_controls.dart @@ -12,7 +12,7 @@ class PlayerWithControls extends StatelessWidget { Widget build(BuildContext context) { final ChewieController chewieController = ChewieController.of(context); - double _calculateAspectRatio(BuildContext context) { + double calculateAspectRatio(BuildContext context) { final size = MediaQuery.of(context).size; final width = size.width; final height = size.height; @@ -20,7 +20,7 @@ class PlayerWithControls extends StatelessWidget { return width > height ? width / height : height / width; } - Widget _buildControls( + Widget buildControls( BuildContext context, ChewieController chewieController, ) { @@ -29,7 +29,7 @@ class PlayerWithControls extends StatelessWidget { : const SizedBox(); } - Widget _buildPlayerWithControls( + Widget buildPlayerWithControls( ChewieController chewieController, BuildContext context, ) { @@ -73,11 +73,11 @@ class PlayerWithControls extends StatelessWidget { ), ), if (!chewieController.isFullScreen) - _buildControls(context, chewieController) + buildControls(context, chewieController) else SafeArea( bottom: false, - child: _buildControls(context, chewieController), + child: buildControls(context, chewieController), ), ], ); @@ -88,8 +88,8 @@ class PlayerWithControls extends StatelessWidget { height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, child: AspectRatio( - aspectRatio: _calculateAspectRatio(context), - child: _buildPlayerWithControls(chewieController, context), + aspectRatio: calculateAspectRatio(context), + child: buildPlayerWithControls(chewieController, context), ), ), );