Skip to content

Commit d85efbf

Browse files
authored
Merge pull request #669 from luis901101/master
Fix for CenterPlayButton UI bug when using Material 3
2 parents 0d997f8 + 0042096 commit d85efbf

File tree

9 files changed

+46
-44
lines changed

9 files changed

+46
-44
lines changed

example/lib/app/theme.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
44
class AppTheme {
55
static final light = ThemeData(
66
brightness: Brightness.light,
7+
useMaterial3: true,
78
colorScheme: const ColorScheme.light(secondary: Colors.red),
89
disabledColor: Colors.grey.shade400,
910
visualDensity: VisualDensity.adaptivePlatformDensity,
@@ -13,6 +14,7 @@ class AppTheme {
1314
brightness: Brightness.dark,
1415
colorScheme: const ColorScheme.dark(secondary: Colors.red),
1516
disabledColor: Colors.grey.shade400,
17+
useMaterial3: true,
1618
visualDensity: VisualDensity.adaptivePlatformDensity,
1719
);
1820
}

lib/chewie.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export 'src/chewie_player.dart';
44
export 'src/chewie_progress_colors.dart';
55
export 'src/cupertino/cupertino_controls.dart';
66
export 'src/material/material_controls.dart';
7+
export 'src/material/material_desktop_controls.dart';
78
export 'src/models/index.dart';

lib/src/center_play_button.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ class CenterPlayButton extends StatelessWidget {
2121

2222
@override
2323
Widget build(BuildContext context) {
24-
return Container(
24+
return ColoredBox(
2525
color: Colors.transparent,
2626
child: Center(
27-
child: AnimatedOpacity(
28-
opacity: show ? 1.0 : 0.0,
29-
duration: const Duration(milliseconds: 300),
30-
child: Container(
31-
decoration: BoxDecoration(
32-
color: backgroundColor,
33-
shape: BoxShape.circle,
34-
),
35-
child: Padding(
36-
padding: const EdgeInsets.all(12.0),
27+
child: UnconstrainedBox(
28+
child: AnimatedOpacity(
29+
opacity: show ? 1.0 : 0.0,
30+
duration: const Duration(milliseconds: 300),
31+
child: DecoratedBox(
32+
decoration: BoxDecoration(
33+
color: backgroundColor,
34+
shape: BoxShape.circle,
35+
),
3736
// Always set the iconSize on the IconButton, not on the Icon itself:
3837
// https://github.com/flutter/flutter/issues/52980
3938
child: IconButton(
4039
iconSize: 32,
40+
padding: const EdgeInsets.all(12.0),
4141
icon: isFinished
4242
? Icon(Icons.replay, color: iconColor)
4343
: AnimatedPlayPause(

lib/src/cupertino/cupertino_controls.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ class _CupertinoControlsState extends State<CupertinoControls>
142142

143143
@override
144144
void didChangeDependencies() {
145-
final _oldController = _chewieController;
145+
final oldController = _chewieController;
146146
_chewieController = ChewieController.of(context);
147147
controller = chewieController.videoPlayerController;
148148

149-
if (_oldController != chewieController) {
149+
if (oldController != chewieController) {
150150
_dispose();
151151
_initialize();
152152
}
@@ -203,14 +203,14 @@ class _CupertinoControlsState extends State<CupertinoControls>
203203

204204
Widget _buildSubtitles(Subtitles subtitles) {
205205
if (!_subtitleOn) {
206-
return Container();
206+
return const SizedBox();
207207
}
208208
if (_subtitlesPosition == null) {
209-
return Container();
209+
return const SizedBox();
210210
}
211211
final currentSubtitle = subtitles.getByPosition(_subtitlesPosition!);
212212
if (currentSubtitle.isEmpty) {
213-
return Container();
213+
return const SizedBox();
214214
}
215215

216216
if (chewieController.subtitleBuilder != null) {
@@ -395,7 +395,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
395395
borderRadius: BorderRadius.circular(10.0),
396396
child: BackdropFilter(
397397
filter: ui.ImageFilter.blur(sigmaX: 10.0),
398-
child: Container(
398+
child: ColoredBox(
399399
color: backgroundColor,
400400
child: Container(
401401
height: barHeight,
@@ -468,7 +468,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
468468
Widget _buildSubtitleToggle(Color iconColor, double barHeight) {
469469
//if don't have subtitle hiden button
470470
if (chewieController.subtitle?.isEmpty ?? true) {
471-
return Container();
471+
return const SizedBox();
472472
}
473473
return GestureDetector(
474474
onTap: _subtitleToggle,

lib/src/helpers/adaptive_controls.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:chewie/chewie.dart';
2-
import 'package:chewie/src/material/material_desktop_controls.dart';
32
import 'package:flutter/material.dart';
43

54
class AdaptiveControls extends StatelessWidget {

lib/src/material/material_controls.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ class _MaterialControlsState extends State<MaterialControls>
128128

129129
@override
130130
void didChangeDependencies() {
131-
final _oldController = _chewieController;
131+
final oldController = _chewieController;
132132
_chewieController = ChewieController.of(context);
133133
controller = chewieController.videoPlayerController;
134134

135-
if (_oldController != chewieController) {
135+
if (oldController != chewieController) {
136136
_dispose();
137137
_initialize();
138138
}
@@ -213,11 +213,11 @@ class _MaterialControlsState extends State<MaterialControls>
213213

214214
Widget _buildSubtitles(BuildContext context, Subtitles subtitles) {
215215
if (!_subtitleOn) {
216-
return Container();
216+
return const SizedBox();
217217
}
218218
final currentSubtitle = subtitles.getByPosition(_subtitlesPosition);
219219
if (currentSubtitle.isEmpty) {
220-
return Container();
220+
return const SizedBox();
221221
}
222222

223223
if (chewieController.subtitleBuilder != null) {
@@ -446,7 +446,7 @@ class _MaterialControlsState extends State<MaterialControls>
446446
Widget _buildSubtitleToggle() {
447447
//if don't have subtitle hiden button
448448
if (chewieController.subtitle?.isEmpty ?? true) {
449-
return Container();
449+
return const SizedBox();
450450
}
451451
return GestureDetector(
452452
onTap: _onSubtitleTap,

lib/src/material/material_desktop_controls.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
128128

129129
@override
130130
void didChangeDependencies() {
131-
final _oldController = _chewieController;
131+
final oldController = _chewieController;
132132
_chewieController = ChewieController.of(context);
133133
controller = chewieController.videoPlayerController;
134134

135-
if (_oldController != chewieController) {
135+
if (oldController != chewieController) {
136136
_dispose();
137137
_initialize();
138138
}
@@ -206,11 +206,11 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
206206

207207
Widget _buildSubtitles(BuildContext context, Subtitles subtitles) {
208208
if (!_subtitleOn) {
209-
return Container();
209+
return const SizedBox();
210210
}
211211
final currentSubtitle = subtitles.getByPosition(_subtitlesPosition);
212212
if (currentSubtitle.isEmpty) {
213-
return Container();
213+
return const SizedBox();
214214
}
215215

216216
if (chewieController.subtitleBuilder != null) {

lib/src/material/widgets/playback_speed_dialog.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class PlaybackSpeedDialog extends StatelessWidget {
2020
shrinkWrap: true,
2121
physics: const ScrollPhysics(),
2222
itemBuilder: (context, index) {
23-
final _speed = _speeds[index];
23+
final speed = _speeds[index];
2424
return ListTile(
2525
dense: true,
2626
title: Row(
2727
children: [
28-
if (_speed == _selected)
28+
if (speed == _selected)
2929
Icon(
3030
Icons.check,
3131
size: 20.0,
@@ -34,12 +34,12 @@ class PlaybackSpeedDialog extends StatelessWidget {
3434
else
3535
Container(width: 20.0),
3636
const SizedBox(width: 16.0),
37-
Text(_speed.toString()),
37+
Text(speed.toString()),
3838
],
3939
),
40-
selected: _speed == _selected,
40+
selected: speed == _selected,
4141
onTap: () {
42-
Navigator.of(context).pop(_speed);
42+
Navigator.of(context).pop(speed);
4343
},
4444
);
4545
},

lib/src/player_with_controls.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ class PlayerWithControls extends StatelessWidget {
1212
Widget build(BuildContext context) {
1313
final ChewieController chewieController = ChewieController.of(context);
1414

15-
double _calculateAspectRatio(BuildContext context) {
15+
double calculateAspectRatio(BuildContext context) {
1616
final size = MediaQuery.of(context).size;
1717
final width = size.width;
1818
final height = size.height;
1919

2020
return width > height ? width / height : height / width;
2121
}
2222

23-
Widget _buildControls(
23+
Widget buildControls(
2424
BuildContext context,
2525
ChewieController chewieController,
2626
) {
2727
return chewieController.showControls
2828
? chewieController.customControls ?? const AdaptiveControls()
29-
: Container();
29+
: const SizedBox();
3030
}
3131

32-
Widget _buildPlayerWithControls(
32+
Widget buildPlayerWithControls(
3333
ChewieController chewieController,
3434
BuildContext context,
3535
) {
@@ -65,19 +65,19 @@ class PlayerWithControls extends StatelessWidget {
6565
duration: const Duration(
6666
milliseconds: 250,
6767
),
68-
child: Container(
69-
decoration: const BoxDecoration(color: Colors.black54),
70-
child: Container(),
68+
child: const DecoratedBox(
69+
decoration: BoxDecoration(color: Colors.black54),
70+
child: SizedBox(),
7171
),
7272
),
7373
),
7474
),
7575
if (!chewieController.isFullScreen)
76-
_buildControls(context, chewieController)
76+
buildControls(context, chewieController)
7777
else
7878
SafeArea(
7979
bottom: false,
80-
child: _buildControls(context, chewieController),
80+
child: buildControls(context, chewieController),
8181
),
8282
],
8383
);
@@ -88,8 +88,8 @@ class PlayerWithControls extends StatelessWidget {
8888
height: MediaQuery.of(context).size.height,
8989
width: MediaQuery.of(context).size.width,
9090
child: AspectRatio(
91-
aspectRatio: _calculateAspectRatio(context),
92-
child: _buildPlayerWithControls(chewieController, context),
91+
aspectRatio: calculateAspectRatio(context),
92+
child: buildPlayerWithControls(chewieController, context),
9393
),
9494
),
9595
);

0 commit comments

Comments
 (0)