From 3ca3d72b9c904c053377bc4fbadc845ba1b03613 Mon Sep 17 00:00:00 2001 From: PartyDonut <42371342+PartyDonut@users.noreply.github.com> Date: Fri, 28 Feb 2025 10:07:41 +0100 Subject: [PATCH] fix: Hide subtitles with empty text (#242) Co-authored-by: PartyDonut --- .../settings/subtitle_settings_model.dart | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/lib/models/settings/subtitle_settings_model.dart b/lib/models/settings/subtitle_settings_model.dart index e186ba1..cba3468 100644 --- a/lib/models/settings/subtitle_settings_model.dart +++ b/lib/models/settings/subtitle_settings_model.dart @@ -209,43 +209,46 @@ class SubtitleText extends ConsumerWidget { // Ensure the text doesn't go off-screen position = position.clamp(0, availableHeight - textHeight); - return IgnorePointer( - child: Stack( - alignment: Alignment.bottomCenter, - children: [ - Positioned( - bottom: position, - child: Container( - constraints: BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraints.maxHeight), - decoration: BoxDecoration( - color: subModel.backGroundColor, - borderRadius: BorderRadius.circular(16), - ), - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: Text( - text, - style: subModel.backGroundStyle.copyWith(fontSize: textScale), - textAlign: TextAlign.center, + return Visibility( + visible: text.isEmpty ? false : true, + child: IgnorePointer( + child: Stack( + alignment: Alignment.bottomCenter, + children: [ + Positioned( + bottom: position, + child: Container( + constraints: BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraints.maxHeight), + decoration: BoxDecoration( + color: subModel.backGroundColor, + borderRadius: BorderRadius.circular(16), + ), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Text( + text, + style: subModel.backGroundStyle.copyWith(fontSize: textScale), + textAlign: TextAlign.center, + ), ), ), ), - ), - Positioned( - bottom: position, - child: Container( - constraints: BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraints.maxHeight), - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: Text( - text, - style: subModel.style.copyWith(fontSize: textScale), - textAlign: TextAlign.center, + Positioned( + bottom: position, + child: Container( + constraints: BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraints.maxHeight), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Text( + text, + style: subModel.style.copyWith(fontSize: textScale), + textAlign: TextAlign.center, + ), ), ), - ), - ) - ], + ) + ], + ), ), ); },