Skip to content

Commit cfe19ba

Browse files
vanlooverenkoenamantoux
authored andcommitted
[video_player] bugfix caption still showing when text is empty (flutter#3374)
1 parent d2ab05e commit cfe19ba

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

packages/video_player/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.3
2+
3+
* Fixed empty caption text still showing the caption widget.
4+
15
## 2.2.2
26

37
* Fix a disposed `VideoPlayerController` throwing an exception when being replaced in the `VideoPlayer`.

packages/video_player/video_player/lib/video_player.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,11 +953,12 @@ class ClosedCaption extends StatelessWidget {
953953
/// Creates a a new closed caption, designed to be used with
954954
/// [VideoPlayerValue.caption].
955955
///
956-
/// If [text] is null, nothing will be displayed.
956+
/// If [text] is null or empty, nothing will be displayed.
957957
const ClosedCaption({Key? key, this.text, this.textStyle}) : super(key: key);
958958

959959
/// The text that will be shown in the closed caption, or null if no caption
960960
/// should be shown.
961+
/// If the text is empty the caption will not be shown.
961962
final String? text;
962963

963964
/// Specifies how the text in the closed caption should look.
@@ -968,16 +969,17 @@ class ClosedCaption extends StatelessWidget {
968969

969970
@override
970971
Widget build(BuildContext context) {
972+
final text = this.text;
973+
if (text == null || text.isEmpty) {
974+
return SizedBox.shrink();
975+
}
976+
971977
final TextStyle effectiveTextStyle = textStyle ??
972978
DefaultTextStyle.of(context).style.copyWith(
973979
fontSize: 36.0,
974980
color: Colors.white,
975981
);
976982

977-
if (text == null) {
978-
return SizedBox.shrink();
979-
}
980-
981983
return Align(
982984
alignment: Alignment.bottomCenter,
983985
child: Padding(
@@ -989,7 +991,7 @@ class ClosedCaption extends StatelessWidget {
989991
),
990992
child: Padding(
991993
padding: EdgeInsets.symmetric(horizontal: 2.0),
992-
child: Text(text!, style: effectiveTextStyle),
994+
child: Text(text, style: effectiveTextStyle),
993995
),
994996
),
995997
),

packages/video_player/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android, iOS, and web.
44
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
6-
version: 2.2.2
6+
version: 2.2.3
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

packages/video_player/video_player/test/video_player_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ void main() {
162162
expect(find.byType(Text), findsNothing);
163163
});
164164

165+
testWidgets('handles empty text', (WidgetTester tester) async {
166+
await tester.pumpWidget(MaterialApp(home: ClosedCaption(text: '')));
167+
expect(find.byType(Text), findsNothing);
168+
});
169+
165170
testWidgets('Passes text contrast ratio guidelines',
166171
(WidgetTester tester) async {
167172
final String text = 'foo';

0 commit comments

Comments
 (0)