Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 5d64092

Browse files
[video_player] bugfix caption still showing when text is empty (#3374)
1 parent af758d5 commit 5d64092

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

packages/video_player/video_player/CHANGELOG.md

+4
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

+8-6
Original file line numberDiff line numberDiff line change
@@ -946,11 +946,12 @@ class ClosedCaption extends StatelessWidget {
946946
/// Creates a a new closed caption, designed to be used with
947947
/// [VideoPlayerValue.caption].
948948
///
949-
/// If [text] is null, nothing will be displayed.
949+
/// If [text] is null or empty, nothing will be displayed.
950950
const ClosedCaption({Key? key, this.text, this.textStyle}) : super(key: key);
951951

952952
/// The text that will be shown in the closed caption, or null if no caption
953953
/// should be shown.
954+
/// If the text is empty the caption will not be shown.
954955
final String? text;
955956

956957
/// Specifies how the text in the closed caption should look.
@@ -961,16 +962,17 @@ class ClosedCaption extends StatelessWidget {
961962

962963
@override
963964
Widget build(BuildContext context) {
965+
final text = this.text;
966+
if (text == null || text.isEmpty) {
967+
return SizedBox.shrink();
968+
}
969+
964970
final TextStyle effectiveTextStyle = textStyle ??
965971
DefaultTextStyle.of(context).style.copyWith(
966972
fontSize: 36.0,
967973
color: Colors.white,
968974
);
969975

970-
if (text == null) {
971-
return SizedBox.shrink();
972-
}
973-
974976
return Align(
975977
alignment: Alignment.bottomCenter,
976978
child: Padding(
@@ -982,7 +984,7 @@ class ClosedCaption extends StatelessWidget {
982984
),
983985
child: Padding(
984986
padding: EdgeInsets.symmetric(horizontal: 2.0),
985-
child: Text(text!, style: effectiveTextStyle),
987+
child: Text(text, style: effectiveTextStyle),
986988
),
987989
),
988990
),

packages/video_player/video_player/pubspec.yaml

+1-1
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

+5
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)