Skip to content

Commit

Permalink
Merge pull request #669 from luis901101/master
Browse files Browse the repository at this point in the history
Fix for CenterPlayButton UI bug when using Material 3
  • Loading branch information
diegotori authored Sep 9, 2022
2 parents 0d997f8 + 0042096 commit d85efbf
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 44 deletions.
2 changes: 2 additions & 0 deletions example/lib/app/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
);
}
1 change: 1 addition & 0 deletions lib/chewie.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
22 changes: 11 additions & 11 deletions lib/src/center_play_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ class CenterPlayButton extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Container(
return ColoredBox(
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),
child: UnconstrainedBox(
child: AnimatedOpacity(
opacity: show ? 1.0 : 0.0,
duration: const Duration(milliseconds: 300),
child: DecoratedBox(
decoration: BoxDecoration(
color: backgroundColor,
shape: BoxShape.circle,
),
// 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),
icon: isFinished
? Icon(Icons.replay, color: iconColor)
: AnimatedPlayPause(
Expand Down
14 changes: 7 additions & 7 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ class _CupertinoControlsState extends State<CupertinoControls>

@override
void didChangeDependencies() {
final _oldController = _chewieController;
final oldController = _chewieController;
_chewieController = ChewieController.of(context);
controller = chewieController.videoPlayerController;

if (_oldController != chewieController) {
if (oldController != chewieController) {
_dispose();
_initialize();
}
Expand Down Expand Up @@ -203,14 +203,14 @@ class _CupertinoControlsState extends State<CupertinoControls>

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) {
Expand Down Expand Up @@ -395,7 +395,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
borderRadius: BorderRadius.circular(10.0),
child: BackdropFilter(
filter: ui.ImageFilter.blur(sigmaX: 10.0),
child: Container(
child: ColoredBox(
color: backgroundColor,
child: Container(
height: barHeight,
Expand Down Expand Up @@ -468,7 +468,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
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,
Expand Down
1 change: 0 additions & 1 deletion lib/src/helpers/adaptive_controls.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ class _MaterialControlsState extends State<MaterialControls>

@override
void didChangeDependencies() {
final _oldController = _chewieController;
final oldController = _chewieController;
_chewieController = ChewieController.of(context);
controller = chewieController.videoPlayerController;

if (_oldController != chewieController) {
if (oldController != chewieController) {
_dispose();
_initialize();
}
Expand Down Expand Up @@ -213,11 +213,11 @@ class _MaterialControlsState extends State<MaterialControls>

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) {
Expand Down Expand Up @@ -446,7 +446,7 @@ class _MaterialControlsState extends State<MaterialControls>
Widget _buildSubtitleToggle() {
//if don't have subtitle hiden button
if (chewieController.subtitle?.isEmpty ?? true) {
return Container();
return const SizedBox();
}
return GestureDetector(
onTap: _onSubtitleTap,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>

@override
void didChangeDependencies() {
final _oldController = _chewieController;
final oldController = _chewieController;
_chewieController = ChewieController.of(context);
controller = chewieController.videoPlayerController;

if (_oldController != chewieController) {
if (oldController != chewieController) {
_dispose();
_initialize();
}
Expand Down Expand Up @@ -206,11 +206,11 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>

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) {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/material/widgets/playback_speed_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
},
);
},
Expand Down
22 changes: 11 additions & 11 deletions lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ 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;

return width > height ? width / height : height / width;
}

Widget _buildControls(
Widget buildControls(
BuildContext context,
ChewieController chewieController,
) {
return chewieController.showControls
? chewieController.customControls ?? const AdaptiveControls()
: Container();
: const SizedBox();
}

Widget _buildPlayerWithControls(
Widget buildPlayerWithControls(
ChewieController chewieController,
BuildContext context,
) {
Expand Down Expand Up @@ -65,19 +65,19 @@ 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(),
),
),
),
),
if (!chewieController.isFullScreen)
_buildControls(context, chewieController)
buildControls(context, chewieController)
else
SafeArea(
bottom: false,
child: _buildControls(context, chewieController),
child: buildControls(context, chewieController),
),
],
);
Expand All @@ -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),
),
),
);
Expand Down

0 comments on commit d85efbf

Please sign in to comment.