[video_player] bugfix caption still showing when text is empty (#3374)
diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md
index 134b2dc..69ad92c 100644
--- a/packages/video_player/video_player/CHANGELOG.md
+++ b/packages/video_player/video_player/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 2.2.3
+
+* Fixed empty caption text still showing the caption widget.
+
## 2.2.2
* Fix a disposed `VideoPlayerController` throwing an exception when being replaced in the `VideoPlayer`.
diff --git a/packages/video_player/video_player/lib/video_player.dart b/packages/video_player/video_player/lib/video_player.dart
index 0d682c9..fe34375 100644
--- a/packages/video_player/video_player/lib/video_player.dart
+++ b/packages/video_player/video_player/lib/video_player.dart
@@ -946,11 +946,12 @@
/// Creates a a new closed caption, designed to be used with
/// [VideoPlayerValue.caption].
///
- /// If [text] is null, nothing will be displayed.
+ /// If [text] is null or empty, nothing will be displayed.
const ClosedCaption({Key? key, this.text, this.textStyle}) : super(key: key);
/// The text that will be shown in the closed caption, or null if no caption
/// should be shown.
+ /// If the text is empty the caption will not be shown.
final String? text;
/// Specifies how the text in the closed caption should look.
@@ -961,16 +962,17 @@
@override
Widget build(BuildContext context) {
+ final text = this.text;
+ if (text == null || text.isEmpty) {
+ return SizedBox.shrink();
+ }
+
final TextStyle effectiveTextStyle = textStyle ??
DefaultTextStyle.of(context).style.copyWith(
fontSize: 36.0,
color: Colors.white,
);
- if (text == null) {
- return SizedBox.shrink();
- }
-
return Align(
alignment: Alignment.bottomCenter,
child: Padding(
@@ -982,7 +984,7 @@
),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 2.0),
- child: Text(text!, style: effectiveTextStyle),
+ child: Text(text, style: effectiveTextStyle),
),
),
),
diff --git a/packages/video_player/video_player/pubspec.yaml b/packages/video_player/video_player/pubspec.yaml
index 2fa5d66..317d46d 100644
--- a/packages/video_player/video_player/pubspec.yaml
+++ b/packages/video_player/video_player/pubspec.yaml
@@ -3,7 +3,7 @@
widgets on Android, iOS, and web.
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
-version: 2.2.2
+version: 2.2.3
environment:
sdk: ">=2.12.0 <3.0.0"
diff --git a/packages/video_player/video_player/test/video_player_test.dart b/packages/video_player/video_player/test/video_player_test.dart
index 5fdc1fb..a929c68 100644
--- a/packages/video_player/video_player/test/video_player_test.dart
+++ b/packages/video_player/video_player/test/video_player_test.dart
@@ -162,6 +162,11 @@
expect(find.byType(Text), findsNothing);
});
+ testWidgets('handles empty text', (WidgetTester tester) async {
+ await tester.pumpWidget(MaterialApp(home: ClosedCaption(text: '')));
+ expect(find.byType(Text), findsNothing);
+ });
+
testWidgets('Passes text contrast ratio guidelines',
(WidgetTester tester) async {
final String text = 'foo';