From e10062206d5004fe6529d2cdc16d7409ff0df9a5 Mon Sep 17 00:00:00 2001 From: JHubi1 Date: Thu, 22 Aug 2024 00:18:23 +0200 Subject: [PATCH] Added beta badge --- lib/main.dart | 6 ++-- lib/screen_settings.dart | 60 +++++++++++++++++++++++++++------------- lib/settings/voice.dart | 9 +++++- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index afead9e..8799b60 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -483,8 +483,9 @@ class _MainAppState extends State { onPressed: () { if (!chatAllowed && chatUuid == - jsonDecode(item)["uuid"]) + jsonDecode(item)["uuid"]) { return; + } if (!allowMultipleChats) { for (var i = 0; i < @@ -646,8 +647,9 @@ class _MainAppState extends State { ? DismissDirection.startToEnd : DismissDirection.none, confirmDismiss: (direction) async { - if (!chatAllowed && chatUuid == jsonDecode(item)["uuid"]) + if (!chatAllowed && chatUuid == jsonDecode(item)["uuid"]) { return false; + } return await deleteChatDialog(context, setState, takeAction: false); }, diff --git a/lib/screen_settings.dart b/lib/screen_settings.dart index 3675c53..679eaac 100644 --- a/lib/screen_settings.dart +++ b/lib/screen_settings.dart @@ -158,6 +158,7 @@ Widget button(String text, IconData? icon, void Function()? onPressed, bool disabled = false, bool replaceIconIfNull = false, String? description, + String? badge, void Function()? onDisabledTap, void Function()? onLongTap, void Function()? onDoubleTap}) { @@ -206,24 +207,43 @@ Widget button(String text, IconData? icon, void Function()? onPressed, (icon != null || replaceIconIfNull) ? const SizedBox(width: 16, height: 42) : const SizedBox.shrink(), - Expanded( - child: (context != null) - ? RichText( - text: TextSpan( - text: text, - style: DefaultTextStyle.of(context).style.copyWith( - color: disabled ? Colors.grey : color), - children: [ - (description != null && - desktopLayoutNotRequired(context)) - ? TextSpan( - text: description, - style: const TextStyle(color: Colors.grey)) - : const TextSpan() - ])) - : Text(text, - style: - TextStyle(color: disabled ? Colors.grey : color))) + Expanded(child: Builder(builder: (context) { + Widget textWidget = Text(text, + style: TextStyle(color: disabled ? Colors.grey : color)); + if (badge != null) { + textWidget = Badge( + label: Text(badge), + offset: const Offset(20, -4), + backgroundColor: Theme.of(context).colorScheme.primary, + textColor: Theme.of(context).colorScheme.onPrimary, + child: textWidget); + } + if (description == null || description!.startsWith("\n")) { + description = description?.removePrefix("\n"); + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + textWidget, + (description != null && desktopLayoutNotRequired(context)) + ? Text(description!, + style: const TextStyle(color: Colors.grey)) + : const SizedBox.shrink() + ]); + } else { + return Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + textWidget, + (description != null && desktopLayoutNotRequired(context)) + ? Text(description!, + style: const TextStyle(color: Colors.grey)) + : const SizedBox.shrink() + ]); + } + })) ]), )), ); @@ -544,7 +564,9 @@ class _ScreenSettingsState extends State { }, context: context, description: - "\n${AppLocalizations.of(context)!.settingsDescriptionVoice}") + "\n${AppLocalizations.of(context)!.settingsDescriptionVoice}", + badge: AppLocalizations.of(context)! + .settingsExperimentalBeta) : const SizedBox.shrink(), button( AppLocalizations.of(context)!.settingsTitleExport, diff --git a/lib/settings/voice.dart b/lib/settings/voice.dart index ced9a52..ccc0fd4 100644 --- a/lib/settings/voice.dart +++ b/lib/settings/voice.dart @@ -66,7 +66,14 @@ class _ScreenSettingsVoiceState extends State { color: Theme.of(context).colorScheme.surface, child: Scaffold( appBar: AppBar( - title: Text(AppLocalizations.of(context)!.settingsTitleVoice)), + title: Badge( + label: Text( + AppLocalizations.of(context)!.settingsExperimentalBeta), + offset: const Offset(20, -4), + backgroundColor: Theme.of(context).colorScheme.primary, + textColor: Theme.of(context).colorScheme.onPrimary, + child: + Text(AppLocalizations.of(context)!.settingsTitleVoice))), body: Padding( padding: const EdgeInsets.only(left: 16, right: 16), child: Column(children: [