Merge remote-tracking branch 'origin/dev' into feat/chess
This commit is contained in:
commit
adead644c7
53 files changed
+2028
-307
No files matched your search
@@ -5624,6 +5624,25 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends an own channel message again as a new message (new timestamp),
|
||||
/// so repeaters forward it even if they already saw the first copy.
|
||||
/// Uses the channel's current flood scope, like a normal send.
|
||||
Future<void> resendChannelMessage(
|
||||
Channel channel,
|
||||
ChannelMessage message,
|
||||
) async {
|
||||
if (!message.isOutgoing) return;
|
||||
final replyToId = message.replyToMessageId;
|
||||
await sendChannelMessage(
|
||||
channel,
|
||||
message.fullText,
|
||||
originalText: message.originalText,
|
||||
translatedLanguageCode: message.translatedLanguageCode,
|
||||
translationModelId: message.translationModelId,
|
||||
replyTo: replyToId == null ? null : _findChannelMessageById(replyToId),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> sendChannelMessage(
|
||||
Channel channel,
|
||||
String text, {
|
||||
|
||||
@@ -503,6 +503,7 @@
|
||||
"chat_selectSendAction": "Изберете действие за изпращане",
|
||||
"chat_sendGif": "Изпрати GIF",
|
||||
"chat_reply": "Отговори",
|
||||
"chat_resend": "Изпрати отново",
|
||||
"chat_addReaction": "Добави Реакция",
|
||||
"chat_me": "Аз",
|
||||
"emojiCategorySmileys": "Емотикони",
|
||||
|
||||
@@ -1086,6 +1086,7 @@
|
||||
"chat_imagePickFailed": "Obrázek se nepodařilo otevřít",
|
||||
"chat_receivedGif": "Přijat GIF",
|
||||
"chat_reply": "Odpovědět",
|
||||
"chat_resend": "Odeslat znovu",
|
||||
"chat_addReaction": "Přidat reakci",
|
||||
"chat_me": "Já",
|
||||
"reaction_report": "Emoji reakce",
|
||||
|
||||
@@ -525,6 +525,7 @@
|
||||
"chat_selectSendAction": "Sendeaktion auswählen",
|
||||
"chat_sendGif": "GIF senden",
|
||||
"chat_reply": "Antworten",
|
||||
"chat_resend": "Erneut senden",
|
||||
"chat_addReaction": "Reaktion hinzufügen",
|
||||
"chat_me": "Ich",
|
||||
"emojiCategorySmileys": "Emoticons",
|
||||
|
||||
@@ -1290,6 +1290,7 @@
|
||||
},
|
||||
"chat_receivedGif": "Received a GIF",
|
||||
"chat_reply": "Reply",
|
||||
"chat_resend": "Resend",
|
||||
"chat_addReaction": "Add Reaction",
|
||||
"chat_me": "Me",
|
||||
"reaction_report": "Emoji Reactions",
|
||||
|
||||
@@ -517,6 +517,7 @@
|
||||
"chat_selectSendAction": "Seleccionar acción de envío",
|
||||
"chat_sendGif": "Enviar GIF",
|
||||
"chat_reply": "Responder",
|
||||
"chat_resend": "Reenviar",
|
||||
"chat_addReaction": "Añadir Reacción",
|
||||
"chat_me": "Yo",
|
||||
"emojiCategorySmileys": "Emoticones",
|
||||
|
||||
@@ -517,6 +517,7 @@
|
||||
"chat_selectSendAction": "Sélectionner une action d’envoi",
|
||||
"chat_sendGif": "Envoyer un GIF",
|
||||
"chat_reply": "Répondre",
|
||||
"chat_resend": "Renvoyer",
|
||||
"chat_addReaction": "Ajouter une réaction",
|
||||
"chat_me": "Moi",
|
||||
"emojiCategorySmileys": "Émojis",
|
||||
|
||||
@@ -703,6 +703,7 @@
|
||||
"chat_selectSendAction": "Küldési művelet kiválasztása",
|
||||
"chat_sendGif": "GIF küldése",
|
||||
"chat_reply": "Válasz",
|
||||
"chat_resend": "Újraküldés",
|
||||
"chat_addReaction": "Reakció hozzáadása",
|
||||
"chat_me": "Nekem",
|
||||
"emojiCategorySmileys": "Hangulatjelek",
|
||||
|
||||
@@ -562,6 +562,7 @@
|
||||
"chat_selectSendAction": "Seleziona azione di invio",
|
||||
"chat_sendGif": "Invia GIF",
|
||||
"chat_reply": "Rispondi",
|
||||
"chat_resend": "Reinvia",
|
||||
"chat_addReaction": "Aggiungi Reazione",
|
||||
"chat_me": "Io",
|
||||
"emojiCategorySmileys": "Emoji",
|
||||
|
||||
@@ -677,6 +677,7 @@
|
||||
"chat_selectSendAction": "送信アクションを選択",
|
||||
"chat_sendGif": "GIF を送信",
|
||||
"chat_reply": "返信",
|
||||
"chat_resend": "再送信",
|
||||
"chat_addReaction": "リアクションを追加",
|
||||
"chat_me": "私",
|
||||
"emojiCategorySmileys": "顔文字",
|
||||
|
||||
@@ -659,6 +659,7 @@
|
||||
"chat_selectSendAction": "전송 작업 선택",
|
||||
"chat_sendGif": "GIF 보내기",
|
||||
"chat_reply": "답변",
|
||||
"chat_resend": "다시 보내기",
|
||||
"chat_addReaction": "댓글 추가",
|
||||
"chat_me": "나",
|
||||
"emojiCategorySmileys": "이모티콘",
|
||||
|
||||
@@ -4387,6 +4387,12 @@ abstract class AppLocalizations {
|
||||
/// **'Reply'**
|
||||
String get chat_reply;
|
||||
|
||||
/// No description provided for @chat_resend.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Resend'**
|
||||
String get chat_resend;
|
||||
|
||||
/// No description provided for @chat_addReaction.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
|
||||
@@ -2521,6 +2521,9 @@ class AppLocalizationsBg extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Отговори';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Изпрати отново';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Добави Реакция';
|
||||
|
||||
|
||||
@@ -2512,6 +2512,9 @@ class AppLocalizationsCs extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Odpovědět';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Odeslat znovu';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Přidat reakci';
|
||||
|
||||
|
||||
@@ -2524,6 +2524,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Antworten';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Erneut senden';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Reaktion hinzufügen';
|
||||
|
||||
|
||||
@@ -2477,6 +2477,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Reply';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Resend';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Add Reaction';
|
||||
|
||||
|
||||
@@ -2515,6 +2515,9 @@ class AppLocalizationsEs extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Responder';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Reenviar';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Añadir Reacción';
|
||||
|
||||
|
||||
@@ -2519,6 +2519,9 @@ class AppLocalizationsFr extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Répondre';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Renvoyer';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Ajouter une réaction';
|
||||
|
||||
|
||||
@@ -2511,6 +2511,9 @@ class AppLocalizationsHu extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Válasz';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Újraküldés';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Reakció hozzáadása';
|
||||
|
||||
|
||||
@@ -2517,6 +2517,9 @@ class AppLocalizationsIt extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Rispondi';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Reinvia';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Aggiungi Reazione';
|
||||
|
||||
|
||||
@@ -2400,6 +2400,9 @@ class AppLocalizationsJa extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => '返信';
|
||||
|
||||
@override
|
||||
String get chat_resend => '再送信';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'リアクションを追加';
|
||||
|
||||
|
||||
@@ -2401,6 +2401,9 @@ class AppLocalizationsKo extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => '답변';
|
||||
|
||||
@override
|
||||
String get chat_resend => '다시 보내기';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => '댓글 추가';
|
||||
|
||||
|
||||
@@ -2503,6 +2503,9 @@ class AppLocalizationsNl extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Reageren';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Opnieuw verzenden';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Reactie toevoegen';
|
||||
|
||||
|
||||
@@ -2540,6 +2540,9 @@ class AppLocalizationsPl extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Odpowiedz';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Wyślij ponownie';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Dodaj Reakcję';
|
||||
|
||||
|
||||
@@ -2512,6 +2512,9 @@ class AppLocalizationsPt extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Responder';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Reenviar';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Adicionar Reação';
|
||||
|
||||
@@ -10604,6 +10607,9 @@ class AppLocalizationsPtPt extends AppLocalizationsPt {
|
||||
@override
|
||||
String get chat_reply => 'Responder';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Reenviar';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Adicionar reação';
|
||||
|
||||
|
||||
@@ -2520,6 +2520,9 @@ class AppLocalizationsRu extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Ответить';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Отправить снова';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Добавить реакцию';
|
||||
|
||||
|
||||
@@ -2513,6 +2513,9 @@ class AppLocalizationsSk extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Odpovedať';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Odoslať znova';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Pridať Reakciu';
|
||||
|
||||
|
||||
@@ -2513,6 +2513,9 @@ class AppLocalizationsSl extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Odgovori';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Pošlji znova';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Dodaj reakcijo';
|
||||
|
||||
|
||||
@@ -2491,6 +2491,9 @@ class AppLocalizationsSv extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Svara';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Skicka igen';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Lägg till reaktion';
|
||||
|
||||
|
||||
@@ -2516,6 +2516,9 @@ class AppLocalizationsUk extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => 'Відповісти';
|
||||
|
||||
@override
|
||||
String get chat_resend => 'Надіслати знову';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => 'Додати реакцію';
|
||||
|
||||
|
||||
@@ -2365,6 +2365,9 @@ class AppLocalizationsZh extends AppLocalizations {
|
||||
@override
|
||||
String get chat_reply => '回复';
|
||||
|
||||
@override
|
||||
String get chat_resend => '重新发送';
|
||||
|
||||
@override
|
||||
String get chat_addReaction => '添加表情';
|
||||
|
||||
|
||||
@@ -523,6 +523,7 @@
|
||||
"chat_removeGif": "GIF verwijderen",
|
||||
"chat_cancelReply": "Antwoord annuleren",
|
||||
"chat_reply": "Reageren",
|
||||
"chat_resend": "Opnieuw verzenden",
|
||||
"chat_addReaction": "Reactie toevoegen",
|
||||
"chat_me": "Ik",
|
||||
"emojiCategorySmileys": "Smileys",
|
||||
|
||||
@@ -513,6 +513,7 @@
|
||||
"chat_selectSendAction": "Wybierz czynność wysyłania",
|
||||
"chat_sendGif": "Wyślij GIF",
|
||||
"chat_reply": "Odpowiedz",
|
||||
"chat_resend": "Wyślij ponownie",
|
||||
"chat_addReaction": "Dodaj Reakcję",
|
||||
"chat_me": "Ja",
|
||||
"emojiCategorySmileys": "Emoji",
|
||||
|
||||
@@ -495,6 +495,7 @@
|
||||
"chat_selectSendAction": "Selecionar ação de envio",
|
||||
"chat_sendGif": "Enviar GIF",
|
||||
"chat_reply": "Responder",
|
||||
"chat_resend": "Reenviar",
|
||||
"chat_addReaction": "Adicionar Reação",
|
||||
"chat_me": "Eu",
|
||||
"emojiCategorySmileys": "Emojis",
|
||||
|
||||
@@ -682,6 +682,7 @@
|
||||
"chat_imagePickFailed": "Não foi possível abrir essa imagem",
|
||||
"chat_receivedGif": "Recebeu um GIF",
|
||||
"chat_reply": "Responder",
|
||||
"chat_resend": "Reenviar",
|
||||
"chat_addReaction": "Adicionar reação",
|
||||
"chat_me": "Eu",
|
||||
"reaction_report": "Reações com emojis",
|
||||
|
||||
@@ -354,6 +354,7 @@
|
||||
"chat_selectSendAction": "Выберите действие отправки",
|
||||
"chat_sendGif": "Отправить GIF",
|
||||
"chat_reply": "Ответить",
|
||||
"chat_resend": "Отправить снова",
|
||||
"chat_addReaction": "Добавить реакцию",
|
||||
"chat_me": "Я",
|
||||
"emojiCategorySmileys": "Смайлы",
|
||||
|
||||
@@ -512,6 +512,7 @@
|
||||
"chat_selectSendAction": "Vybrať akciu odoslania",
|
||||
"chat_sendGif": "Odoslať GIF",
|
||||
"chat_reply": "Odpovedať",
|
||||
"chat_resend": "Odoslať znova",
|
||||
"chat_addReaction": "Pridať Reakciu",
|
||||
"chat_me": "Mne",
|
||||
"emojiCategorySmileys": "Emoji",
|
||||
|
||||
@@ -495,6 +495,7 @@
|
||||
"chat_selectSendAction": "Izberite dejanje pošiljanja",
|
||||
"chat_sendGif": "Pošlji GIF",
|
||||
"chat_reply": "Odgovori",
|
||||
"chat_resend": "Pošlji znova",
|
||||
"chat_addReaction": "Dodaj reakcijo",
|
||||
"chat_me": "jaz",
|
||||
"emojiCategorySmileys": "Emoji",
|
||||
|
||||
@@ -495,6 +495,7 @@
|
||||
"chat_selectSendAction": "Välj sändningsåtgärd",
|
||||
"chat_sendGif": "Skicka GIF",
|
||||
"chat_reply": "Svara",
|
||||
"chat_resend": "Skicka igen",
|
||||
"chat_addReaction": "Lägg till reaktion",
|
||||
"chat_me": "Mig",
|
||||
"reaction_report": "Emoji-reaktioner",
|
||||
|
||||
@@ -506,6 +506,7 @@
|
||||
"chat_selectSendAction": "Виберіть дію надсилання",
|
||||
"chat_sendGif": "Надіслати GIF",
|
||||
"chat_reply": "Відповісти",
|
||||
"chat_resend": "Надіслати знову",
|
||||
"chat_addReaction": "Додати реакцію",
|
||||
"chat_me": "Я",
|
||||
"emojiCategorySmileys": "Емодзі",
|
||||
|
||||
@@ -522,6 +522,7 @@
|
||||
"chat_selectSendAction": "选择发送操作",
|
||||
"chat_sendGif": "发送 GIF",
|
||||
"chat_reply": "回复",
|
||||
"chat_resend": "重新发送",
|
||||
"chat_addReaction": "添加表情",
|
||||
"chat_me": "我",
|
||||
"emojiCategorySmileys": "表情",
|
||||
|
||||
@@ -461,6 +461,16 @@ class RadioSettings {
|
||||
txPowerDbm: 20,
|
||||
),
|
||||
),
|
||||
(
|
||||
'Slovakia',
|
||||
RadioSettings(
|
||||
frequencyMHz: 869.618,
|
||||
bandwidth: LoRaBandwidth.bw62_5,
|
||||
spreadingFactor: LoRaSpreadingFactor.sf7,
|
||||
codingRate: LoRaCodingRate.cr4_5,
|
||||
txPowerDbm: 14,
|
||||
),
|
||||
),
|
||||
(
|
||||
'Switzerland',
|
||||
RadioSettings(
|
||||
|
||||
@@ -63,9 +63,9 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
|
||||
// NOTIFICATIONS
|
||||
SectionHeader(context.l10n.appSettings_notifications),
|
||||
MeshCard(
|
||||
const MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: _settingsCard(_buildNotificationsContent),
|
||||
child: NotificationsSettingsSection(),
|
||||
),
|
||||
|
||||
// MESSAGING
|
||||
@@ -266,156 +266,6 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotificationsContent(
|
||||
BuildContext context,
|
||||
AppSettingsService settingsService,
|
||||
) {
|
||||
final notifEnabled = settingsService.settings.notificationsEnabled;
|
||||
return Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: const Icon(Icons.notifications_outlined, size: 24),
|
||||
title: Text(context.l10n.appSettings_enableNotifications),
|
||||
subtitle: Text(context.l10n.appSettings_enableNotificationsSubtitle),
|
||||
value: settingsService.settings.notificationsEnabled,
|
||||
onChanged: (value) async {
|
||||
if (value) {
|
||||
final granted = await NotificationService().requestPermissions();
|
||||
if (!granted) {
|
||||
if (context.mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
context.l10n.appSettings_notificationPermissionDenied,
|
||||
),
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
await settingsService.setNotificationsEnabled(value);
|
||||
if (context.mounted) {
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
value
|
||||
? context.l10n.appSettings_notificationsEnabled
|
||||
: context.l10n.appSettings_notificationsDisabled,
|
||||
),
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: Icon(
|
||||
Icons.message_outlined,
|
||||
size: 24,
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
title: Text(
|
||||
context.l10n.appSettings_messageNotifications,
|
||||
style: TextStyle(
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
context.l10n.appSettings_messageNotificationsSubtitle,
|
||||
style: TextStyle(
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
),
|
||||
value: settingsService.settings.notifyOnNewMessage,
|
||||
onChanged: notifEnabled
|
||||
? (value) => settingsService.setNotifyOnNewMessage(value)
|
||||
: null,
|
||||
),
|
||||
if (PlatformInfo.isAndroid) ...[
|
||||
const Divider(height: 1, indent: 16),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
leading: const Icon(Icons.battery_saver_outlined, size: 24),
|
||||
title: Text(context.l10n.appSettings_batteryOptimization),
|
||||
subtitle: Text(
|
||||
context.l10n.appSettings_batteryOptimizationSubtitle,
|
||||
),
|
||||
trailing: const Icon(Icons.open_in_new, size: 24),
|
||||
onTap: BackgroundService.openBatteryOptimizationSettings,
|
||||
),
|
||||
],
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: Icon(
|
||||
Icons.forum_outlined,
|
||||
size: 24,
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
title: Text(
|
||||
context.l10n.appSettings_channelMessageNotifications,
|
||||
style: TextStyle(
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
context.l10n.appSettings_channelMessageNotificationsSubtitle,
|
||||
style: TextStyle(
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
),
|
||||
value: settingsService.settings.notifyOnNewChannelMessage,
|
||||
onChanged: notifEnabled
|
||||
? (value) => settingsService.setNotifyOnNewChannelMessage(value)
|
||||
: null,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 4,
|
||||
),
|
||||
secondary: Icon(
|
||||
Icons.cell_tower,
|
||||
size: 24,
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
title: Text(
|
||||
context.l10n.appSettings_advertisementNotifications,
|
||||
style: TextStyle(
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
context.l10n.appSettings_advertisementNotificationsSubtitle,
|
||||
style: TextStyle(
|
||||
color: notifEnabled ? null : Theme.of(context).disabledColor,
|
||||
),
|
||||
),
|
||||
value: settingsService.settings.notifyOnNewAdvert,
|
||||
onChanged: notifEnabled
|
||||
? (value) => settingsService.setNotifyOnNewAdvert(value)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMessagingContent(
|
||||
BuildContext context,
|
||||
AppSettingsService settingsService,
|
||||
@@ -1870,3 +1720,205 @@ class _ScrollIntoViewOnceState extends State<_ScrollIntoViewOnce> {
|
||||
@override
|
||||
Widget build(BuildContext context) => widget.child;
|
||||
}
|
||||
|
||||
class NotificationsSettingsSection extends StatefulWidget {
|
||||
final Future<bool> Function()? hasPermission;
|
||||
final Future<bool> Function()? requestPermission;
|
||||
|
||||
const NotificationsSettingsSection({
|
||||
super.key,
|
||||
this.hasPermission,
|
||||
this.requestPermission,
|
||||
});
|
||||
|
||||
@override
|
||||
State<NotificationsSettingsSection> createState() =>
|
||||
_NotificationsSettingsSectionState();
|
||||
}
|
||||
|
||||
class _NotificationsSettingsSectionState
|
||||
extends State<NotificationsSettingsSection>
|
||||
with WidgetsBindingObserver {
|
||||
bool _hasNotificationPermission = false;
|
||||
bool _permissionCheckComplete = false;
|
||||
int _permissionCheckGeneration = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_refreshNotificationPermission(inInit: true);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant NotificationsSettingsSection oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.hasPermission != oldWidget.hasPermission) {
|
||||
_refreshNotificationPermission();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_refreshNotificationPermission();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _checkPermission() {
|
||||
final checker = widget.hasPermission;
|
||||
if (checker != null) return checker();
|
||||
return NotificationService().hasNotificationPermission();
|
||||
}
|
||||
|
||||
Future<bool> _requestPermission() {
|
||||
final requester = widget.requestPermission;
|
||||
if (requester != null) return requester();
|
||||
return NotificationService().requestPermissions();
|
||||
}
|
||||
|
||||
void _refreshNotificationPermission({bool inInit = false}) {
|
||||
final generation = ++_permissionCheckGeneration;
|
||||
var completedSynchronously = false;
|
||||
var syncResult = false;
|
||||
var isSyncWindow = true;
|
||||
_checkPermission().then((granted) {
|
||||
if (generation != _permissionCheckGeneration) return;
|
||||
if (isSyncWindow && inInit) {
|
||||
completedSynchronously = true;
|
||||
syncResult = granted;
|
||||
return;
|
||||
}
|
||||
if (!mounted) return;
|
||||
if (_permissionCheckComplete && _hasNotificationPermission == granted) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_hasNotificationPermission = granted;
|
||||
_permissionCheckComplete = true;
|
||||
});
|
||||
});
|
||||
isSyncWindow = false;
|
||||
if (completedSynchronously) {
|
||||
_hasNotificationPermission = syncResult;
|
||||
_permissionCheckComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final settingsService = context.watch<AppSettingsService>();
|
||||
final settings = settingsService.settings;
|
||||
final l10n = context.l10n;
|
||||
final effectiveEnabled =
|
||||
settings.notificationsEnabled && _hasNotificationPermission;
|
||||
final permissionDenied =
|
||||
_permissionCheckComplete && !_hasNotificationPermission;
|
||||
const tilePadding = EdgeInsets.symmetric(horizontal: 16, vertical: 4);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SwitchListTile(
|
||||
contentPadding: tilePadding,
|
||||
secondary: const Icon(Icons.notifications_outlined, size: 24),
|
||||
title: Text(l10n.appSettings_enableNotifications),
|
||||
subtitle: Text(
|
||||
permissionDenied
|
||||
? l10n.appSettings_notificationPermissionDenied
|
||||
: l10n.appSettings_enableNotificationsSubtitle,
|
||||
),
|
||||
value: effectiveEnabled,
|
||||
onChanged: (value) async {
|
||||
_permissionCheckGeneration++;
|
||||
if (value) {
|
||||
final granted = await _requestPermission();
|
||||
if (!granted) {
|
||||
if (!context.mounted) return;
|
||||
setState(() {
|
||||
_hasNotificationPermission = false;
|
||||
_permissionCheckComplete = true;
|
||||
});
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.appSettings_notificationPermissionDenied),
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (context.mounted) {
|
||||
setState(() {
|
||||
_hasNotificationPermission = true;
|
||||
_permissionCheckComplete = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
await settingsService.setNotificationsEnabled(value);
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(
|
||||
value
|
||||
? l10n.appSettings_notificationsEnabled
|
||||
: l10n.appSettings_notificationsDisabled,
|
||||
),
|
||||
duration: const Duration(seconds: 2),
|
||||
);
|
||||
},
|
||||
),
|
||||
SettingsReveal(
|
||||
visible: effectiveEnabled,
|
||||
children: [
|
||||
SwitchListTile(
|
||||
contentPadding: tilePadding,
|
||||
secondary: const Icon(Icons.message_outlined, size: 24),
|
||||
title: Text(l10n.appSettings_messageNotifications),
|
||||
subtitle: Text(l10n.appSettings_messageNotificationsSubtitle),
|
||||
value: settings.notifyOnNewMessage,
|
||||
onChanged: settingsService.setNotifyOnNewMessage,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: tilePadding,
|
||||
secondary: const Icon(Icons.forum_outlined, size: 24),
|
||||
title: Text(l10n.appSettings_channelMessageNotifications),
|
||||
subtitle: Text(
|
||||
l10n.appSettings_channelMessageNotificationsSubtitle,
|
||||
),
|
||||
value: settings.notifyOnNewChannelMessage,
|
||||
onChanged: settingsService.setNotifyOnNewChannelMessage,
|
||||
),
|
||||
const Divider(height: 1, indent: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: tilePadding,
|
||||
secondary: const Icon(Icons.cell_tower, size: 24),
|
||||
title: Text(l10n.appSettings_advertisementNotifications),
|
||||
subtitle: Text(
|
||||
l10n.appSettings_advertisementNotificationsSubtitle,
|
||||
),
|
||||
value: settings.notifyOnNewAdvert,
|
||||
onChanged: settingsService.setNotifyOnNewAdvert,
|
||||
),
|
||||
if (PlatformInfo.isAndroid) ...[
|
||||
const Divider(height: 1, indent: 16),
|
||||
ListTile(
|
||||
contentPadding: tilePadding,
|
||||
leading: const Icon(Icons.battery_saver_outlined, size: 24),
|
||||
title: Text(l10n.appSettings_batteryOptimization),
|
||||
subtitle: Text(l10n.appSettings_batteryOptimizationSubtitle),
|
||||
trailing: const Icon(Icons.open_in_new, size: 24),
|
||||
onTap: BackgroundService.openBatteryOptimizationSettings,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3027,6 +3027,18 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
_sendGuard.markDispatched();
|
||||
}
|
||||
|
||||
/// Sends an own message again as a new message, e.g. when no repeats
|
||||
/// were heard.
|
||||
Future<void> _resendMessage(ChannelMessage message) {
|
||||
return _sendGuard.runExclusive(() async {
|
||||
if (!ensureRadioConnected(context)) return;
|
||||
if (!_sendGuard.checkCooldown(context)) return;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
unawaited(connector.resendChannelMessage(widget.channel, message));
|
||||
_sendGuard.markDispatched();
|
||||
});
|
||||
}
|
||||
|
||||
void _showMessagePathInfo(ChannelMessage message) {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -3133,6 +3145,16 @@ class _ChannelChatScreenState extends State<ChannelChatScreen>
|
||||
copyChatMessageText(context, message.fullText);
|
||||
},
|
||||
),
|
||||
if (message.isOutgoing)
|
||||
ListTile(
|
||||
enabled: !readOnly,
|
||||
leading: const Icon(Icons.replay),
|
||||
title: Text(context.l10n.chat_resend),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
_resendMessage(message);
|
||||
},
|
||||
),
|
||||
if (canTranslateMessage)
|
||||
ListTile(
|
||||
leading: const Icon(Icons.translate),
|
||||
|
||||
@@ -180,7 +180,9 @@ class NotificationService {
|
||||
// connection whose async subscription can throw an unhandled
|
||||
// SocketException when the bus socket is missing (e.g. running as
|
||||
// root or inside a container without a session bus).
|
||||
if (PlatformInfo.isLinux && !_isDbusSessionAvailable()) {
|
||||
if (PlatformInfo.isLinux &&
|
||||
defaultTargetPlatform == TargetPlatform.linux &&
|
||||
!_isDbusSessionAvailable()) {
|
||||
debugPrint('Skipping notification init: D-Bus session bus unavailable');
|
||||
return;
|
||||
}
|
||||
@@ -250,11 +252,97 @@ class NotificationService {
|
||||
// Cached "are we allowed to post notifications" result. Null = not yet
|
||||
// determined. Avoids calling _notifications.show() when it would only throw
|
||||
// "You must request notifications permissions first" (every web build).
|
||||
// Android denials are never cached so a later grant in system settings is
|
||||
// picked up without restarting the app.
|
||||
// Denials are never cached so a later grant in system settings is picked up
|
||||
// without restarting the app, and [hasNotificationPermission] refreshes or
|
||||
// clears [_canNotify] whenever live OS permission is checked.
|
||||
bool? _canNotify;
|
||||
static const _permissionRequestedKey = 'notification_permission_requested';
|
||||
|
||||
@visibleForTesting
|
||||
Future<bool> Function()? permissionCheckerForTest;
|
||||
|
||||
@visibleForTesting
|
||||
Future<bool> Function()? permissionRequesterForTest;
|
||||
|
||||
@visibleForTesting
|
||||
Future<bool> ensureCanNotifyForTest() => _ensureCanNotify();
|
||||
|
||||
@visibleForTesting
|
||||
bool? get canNotifyCacheForTest => _canNotify;
|
||||
|
||||
@visibleForTesting
|
||||
void resetForTest() {
|
||||
_canNotify = null;
|
||||
_isInitialized = false;
|
||||
permissionCheckerForTest = null;
|
||||
permissionRequesterForTest = null;
|
||||
}
|
||||
|
||||
T? _resolvePlugin<T extends FlutterLocalNotificationsPlatform>() {
|
||||
try {
|
||||
return _notifications.resolvePlatformSpecificImplementation<T>();
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static bool _isDarwinPermissionGranted(NotificationsEnabledOptions? options) {
|
||||
if (options == null) return false;
|
||||
return options.isEnabled ||
|
||||
options.isProvisionalEnabled ||
|
||||
options.isAlertEnabled ||
|
||||
options.isSoundEnabled ||
|
||||
options.isBadgeEnabled;
|
||||
}
|
||||
|
||||
/// Queries the live OS notification permission state without returning a
|
||||
/// stale cached grant. Updates [_canNotify] so [_ensureCanNotify] reflects
|
||||
/// permissions revoked in system settings.
|
||||
Future<bool> hasNotificationPermission() {
|
||||
final testChecker = permissionCheckerForTest;
|
||||
if (testChecker != null) {
|
||||
return testChecker().then((enabled) {
|
||||
if (!kIsWeb) {
|
||||
_canNotify = enabled ? true : null;
|
||||
}
|
||||
return enabled;
|
||||
});
|
||||
}
|
||||
|
||||
if (kIsWeb) return SynchronousFuture<bool>(true);
|
||||
|
||||
final androidPlugin =
|
||||
_resolvePlugin<AndroidFlutterLocalNotificationsPlugin>();
|
||||
if (androidPlugin != null) {
|
||||
return androidPlugin.areNotificationsEnabled().then((value) {
|
||||
final enabled = value ?? false;
|
||||
_canNotify = enabled ? true : null;
|
||||
return enabled;
|
||||
});
|
||||
}
|
||||
|
||||
final iosPlugin = _resolvePlugin<IOSFlutterLocalNotificationsPlugin>();
|
||||
if (iosPlugin != null) {
|
||||
return iosPlugin.checkPermissions().then((options) {
|
||||
final enabled = _isDarwinPermissionGranted(options);
|
||||
_canNotify = enabled ? true : null;
|
||||
return enabled;
|
||||
});
|
||||
}
|
||||
|
||||
final macPlugin = _resolvePlugin<MacOSFlutterLocalNotificationsPlugin>();
|
||||
if (macPlugin != null) {
|
||||
return macPlugin.checkPermissions().then((options) {
|
||||
final enabled = _isDarwinPermissionGranted(options);
|
||||
_canNotify = enabled ? true : null;
|
||||
return enabled;
|
||||
});
|
||||
}
|
||||
|
||||
_canNotify = true;
|
||||
return SynchronousFuture<bool>(true);
|
||||
}
|
||||
|
||||
Future<bool> _ensureCanNotify() async {
|
||||
if (!await _ensureInitialized()) return false;
|
||||
final cached = _canNotify;
|
||||
@@ -264,50 +352,52 @@ class NotificationService {
|
||||
// Skip silently instead of logging an error per incoming message.
|
||||
if (kIsWeb) return _canNotify = false;
|
||||
|
||||
// On Android 13+ notifications require an explicit grant; reflect the real
|
||||
// OS state so we don't spam failed show() calls when denied.
|
||||
final androidPlugin = _notifications
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
if (androidPlugin != null) {
|
||||
final enabled = await androidPlugin.areNotificationsEnabled() ?? false;
|
||||
if (enabled) _canNotify = true;
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// iOS/macOS request permission during initialize(); desktop has no gate.
|
||||
return _canNotify = true;
|
||||
return hasNotificationPermission();
|
||||
}
|
||||
|
||||
Future<bool> requestPermissions() async {
|
||||
final testRequester = permissionRequesterForTest;
|
||||
if (testRequester != null) {
|
||||
final granted = await testRequester();
|
||||
if (!kIsWeb) {
|
||||
_canNotify = granted ? true : null;
|
||||
}
|
||||
return granted;
|
||||
}
|
||||
|
||||
if (!_isInitialized) {
|
||||
await initialize();
|
||||
}
|
||||
|
||||
// Request Android 13+ notification permission
|
||||
final androidPlugin = _notifications
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
final androidPlugin =
|
||||
_resolvePlugin<AndroidFlutterLocalNotificationsPlugin>();
|
||||
if (androidPlugin != null) {
|
||||
final granted = await androidPlugin.requestNotificationsPermission();
|
||||
if (granted == true) _canNotify = true;
|
||||
_canNotify = (granted == true) ? true : null;
|
||||
return granted ?? false;
|
||||
}
|
||||
|
||||
// iOS permissions are requested during initialization
|
||||
final iosPlugin = _notifications
|
||||
.resolvePlatformSpecificImplementation<
|
||||
IOSFlutterLocalNotificationsPlugin
|
||||
>();
|
||||
final iosPlugin = _resolvePlugin<IOSFlutterLocalNotificationsPlugin>();
|
||||
if (iosPlugin != null) {
|
||||
final granted = await iosPlugin.requestPermissions(
|
||||
alert: true,
|
||||
badge: true,
|
||||
sound: true,
|
||||
);
|
||||
if (granted == true) _canNotify = true;
|
||||
_canNotify = (granted == true) ? true : null;
|
||||
return granted ?? false;
|
||||
}
|
||||
|
||||
final macPlugin = _resolvePlugin<MacOSFlutterLocalNotificationsPlugin>();
|
||||
if (macPlugin != null) {
|
||||
final granted = await macPlugin.requestPermissions(
|
||||
alert: true,
|
||||
badge: true,
|
||||
sound: true,
|
||||
);
|
||||
_canNotify = (granted == true) ? true : null;
|
||||
return granted ?? false;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,12 @@ class PlatformInfo {
|
||||
static bool get isChrome => isWeb && BrowserDetection.isChrome;
|
||||
|
||||
/// Whether the app is running on Android.
|
||||
static bool get isAndroid => !kIsWeb && Platform.isAndroid;
|
||||
static bool get isAndroid =>
|
||||
debugIsAndroidOverride ?? (!kIsWeb && Platform.isAndroid);
|
||||
|
||||
/// Lets widget tests exercise Android-only UI on a non-Android test host.
|
||||
@visibleForTesting
|
||||
static bool? debugIsAndroidOverride;
|
||||
|
||||
/// Whether the app is running on iOS.
|
||||
static bool get isIOS => !kIsWeb && Platform.isIOS;
|
||||
|
||||
+228
-28
@@ -1,3 +1,5 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -132,6 +134,9 @@ class ChatComposer extends StatelessWidget {
|
||||
/// Marks the compose bubble (and the offline bar's bubble).
|
||||
static const bubbleKey = ValueKey('chat-composer-bubble');
|
||||
|
||||
/// Marks the surface of the open "+" menu.
|
||||
static const actionMenuKey = ValueKey('chat-composer-action-menu');
|
||||
|
||||
const ChatComposer({
|
||||
super.key,
|
||||
required this.controller,
|
||||
@@ -152,34 +157,26 @@ class ChatComposer extends StatelessWidget {
|
||||
final actions = actionsBuilder();
|
||||
if (actions.isEmpty) return;
|
||||
final button = buttonContext.findRenderObject() as RenderBox;
|
||||
final overlay =
|
||||
Overlay.of(buttonContext).context.findRenderObject() as RenderBox;
|
||||
final buttonOffset = button.localToGlobal(Offset.zero, ancestor: overlay);
|
||||
final menuHeight = actions.length * kMinInteractiveDimension + 16;
|
||||
final menuTop = (buttonOffset.dy - menuHeight).clamp(
|
||||
8.0,
|
||||
overlay.size.height,
|
||||
);
|
||||
final position = RelativeRect.fromLTRB(
|
||||
buttonOffset.dx,
|
||||
menuTop,
|
||||
overlay.size.width - buttonOffset.dx - button.size.width,
|
||||
overlay.size.height - buttonOffset.dy,
|
||||
);
|
||||
final selected = await showMenu<String>(
|
||||
context: buttonContext,
|
||||
position: position,
|
||||
// Keep focus on the text field: if the menu route took focus, the
|
||||
// keyboard would close, the composer would drop down and the menu would
|
||||
// be left floating where the keyboard used to be.
|
||||
requestFocus: false,
|
||||
items: [
|
||||
for (final action in actions)
|
||||
PopupMenuItem(
|
||||
value: action.id,
|
||||
child: MeshMenuItemRow(icon: action.icon, label: action.label),
|
||||
),
|
||||
],
|
||||
final navigator = Navigator.of(buttonContext);
|
||||
final overlay = navigator.overlay!.context.findRenderObject() as RenderBox;
|
||||
final anchor =
|
||||
button.localToGlobal(Offset.zero, ancestor: overlay) & button.size;
|
||||
// The menu route never requests focus: if it took focus from the text
|
||||
// field the keyboard would close, the composer would drop down and the
|
||||
// menu would be left floating where the keyboard used to be.
|
||||
final selected = await navigator.push<String>(
|
||||
_ComposerActionMenuRoute(
|
||||
actions: actions,
|
||||
anchor: anchor,
|
||||
button: button,
|
||||
overlay: overlay,
|
||||
capturedThemes: InheritedTheme.capture(
|
||||
from: buttonContext,
|
||||
to: navigator.context,
|
||||
),
|
||||
barrierLabel: MaterialLocalizations.of(buttonContext).menuDismissLabel,
|
||||
animate: !MediaQuery.disableAnimationsOf(buttonContext),
|
||||
),
|
||||
);
|
||||
if (selected == null || !buttonContext.mounted) return;
|
||||
onAction(selected);
|
||||
@@ -585,3 +582,206 @@ class OfflineComposerBar extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The "+" menu: a popup that grows upward from the bottom-trailing corner,
|
||||
/// just above the "+" button, so it opens out of the button instead of
|
||||
/// sliding down toward it.
|
||||
class _ComposerActionMenuRoute extends PopupRoute<String> {
|
||||
final List<ChatComposerAction> actions;
|
||||
final Rect anchor;
|
||||
final RenderBox button;
|
||||
final RenderBox overlay;
|
||||
final CapturedThemes capturedThemes;
|
||||
final bool animate;
|
||||
|
||||
@override
|
||||
final String barrierLabel;
|
||||
|
||||
_ComposerActionMenuRoute({
|
||||
required this.actions,
|
||||
required this.anchor,
|
||||
required this.button,
|
||||
required this.overlay,
|
||||
required this.capturedThemes,
|
||||
required this.barrierLabel,
|
||||
required this.animate,
|
||||
}) : super(requestFocus: false);
|
||||
|
||||
static const double _gap = 4;
|
||||
static const double _margin = 8;
|
||||
static const double _minWidth = 112;
|
||||
|
||||
@override
|
||||
Color? get barrierColor => null;
|
||||
|
||||
@override
|
||||
bool get barrierDismissible => true;
|
||||
|
||||
@override
|
||||
Duration get transitionDuration =>
|
||||
animate ? const Duration(milliseconds: 250) : Duration.zero;
|
||||
|
||||
@override
|
||||
Duration get reverseTransitionDuration =>
|
||||
animate ? const Duration(milliseconds: 150) : Duration.zero;
|
||||
|
||||
@override
|
||||
Widget buildPage(
|
||||
BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
) {
|
||||
final direction = Directionality.of(context);
|
||||
final padding = MediaQuery.paddingOf(context);
|
||||
return capturedThemes.wrap(
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final viewport = constraints.biggest;
|
||||
final rect = button.attached && overlay.attached
|
||||
? button.localToGlobal(Offset.zero, ancestor: overlay) &
|
||||
button.size
|
||||
: anchor;
|
||||
final rawEnd = direction == TextDirection.ltr
|
||||
? viewport.width - rect.right
|
||||
: rect.left;
|
||||
final end = rawEnd
|
||||
.clamp(
|
||||
_margin,
|
||||
math.max(_margin, viewport.width - _minWidth - _margin),
|
||||
)
|
||||
.toDouble();
|
||||
final maxWidth = math.max(
|
||||
_minWidth,
|
||||
math.min(280.0, viewport.width - end - _margin),
|
||||
);
|
||||
final bottom = (viewport.height - rect.top + _gap)
|
||||
.clamp(
|
||||
_margin,
|
||||
math.max(
|
||||
_margin,
|
||||
viewport.height -
|
||||
padding.top -
|
||||
_margin -
|
||||
kMinInteractiveDimension,
|
||||
),
|
||||
)
|
||||
.toDouble();
|
||||
final maxHeight = math.max(
|
||||
kMinInteractiveDimension,
|
||||
viewport.height - bottom - padding.top - _margin,
|
||||
);
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.directional(
|
||||
textDirection: direction,
|
||||
end: end,
|
||||
bottom: bottom,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minWidth: _minWidth,
|
||||
maxWidth: maxWidth,
|
||||
maxHeight: maxHeight,
|
||||
),
|
||||
child: _ComposerActionMenu(
|
||||
actions: actions,
|
||||
animation: animation,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ComposerActionMenu extends StatelessWidget {
|
||||
final List<ChatComposerAction> actions;
|
||||
final Animation<double> animation;
|
||||
|
||||
const _ComposerActionMenu({required this.actions, required this.animation});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final menuTheme = PopupMenuTheme.of(context);
|
||||
final items = IntrinsicWidth(
|
||||
stepWidth: 56,
|
||||
child: Semantics(
|
||||
scopesRoute: true,
|
||||
namesRoute: true,
|
||||
explicitChildNodes: true,
|
||||
label: MaterialLocalizations.of(context).popupMenuLabel,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: DefaultTextStyle(
|
||||
style: (menuTheme.textStyle ?? theme.textTheme.labelLarge!)
|
||||
.copyWith(color: scheme.onSurface),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (final action in actions)
|
||||
InkWell(
|
||||
onTap: () => Navigator.of(context).pop(action.id),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: kMinInteractiveDimension,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: MeshMenuItemRow(
|
||||
icon: action.icon,
|
||||
label: action.label,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return AnimatedBuilder(
|
||||
animation: animation,
|
||||
builder: (context, child) {
|
||||
final t = animation.value;
|
||||
final heightFactor =
|
||||
(animation.status == AnimationStatus.reverse
|
||||
? Curves.easeIn
|
||||
: Curves.easeOutCubic)
|
||||
.transform(t);
|
||||
return Opacity(
|
||||
opacity: const Interval(0, 0.4).transform(t),
|
||||
child: Material(
|
||||
key: ChatComposer.actionMenuKey,
|
||||
type: MaterialType.card,
|
||||
color: menuTheme.color ?? scheme.surfaceContainerHigh,
|
||||
elevation: menuTheme.elevation ?? 3,
|
||||
shadowColor: menuTheme.shadowColor,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
shape:
|
||||
menuTheme.shape ??
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.bottomEnd,
|
||||
widthFactor: 1,
|
||||
heightFactor: heightFactor,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: items,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/translation_support.dart';
|
||||
import 'mesh_ui.dart';
|
||||
|
||||
class MessageTranslationButton extends StatelessWidget {
|
||||
final bool enabled;
|
||||
@@ -38,15 +41,58 @@ Future<void> showMessageTranslationSheet({
|
||||
required ValueChanged<bool> onEnabledChanged,
|
||||
required ValueChanged<String?> onLanguageSelected,
|
||||
}) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (context) => _MessageTranslationSheet(
|
||||
enabled: enabled,
|
||||
selectedLanguageCode: selectedLanguageCode,
|
||||
onEnabledChanged: onEnabledChanged,
|
||||
onLanguageSelected: onLanguageSelected,
|
||||
),
|
||||
final callerMedia = MediaQuery.of(context);
|
||||
final navMedia =
|
||||
MediaQuery.maybeOf(Navigator.of(context).context) ?? callerMedia;
|
||||
final callerBottom = math.max(
|
||||
callerMedia.viewInsets.bottom,
|
||||
math.max(callerMedia.viewPadding.bottom, callerMedia.padding.bottom),
|
||||
);
|
||||
final navBottom = math.max(
|
||||
navMedia.viewInsets.bottom,
|
||||
math.max(navMedia.viewPadding.bottom, navMedia.padding.bottom),
|
||||
);
|
||||
final extraBottom = math.max(0.0, callerBottom - navBottom);
|
||||
final safeTop = math.max(
|
||||
math.max(callerMedia.viewPadding.top, callerMedia.padding.top),
|
||||
math.max(navMedia.viewPadding.top, navMedia.padding.top),
|
||||
);
|
||||
final bottomSafeInset = math.max(
|
||||
math.max(callerMedia.viewPadding.bottom, callerMedia.padding.bottom),
|
||||
math.max(navMedia.viewPadding.bottom, navMedia.padding.bottom),
|
||||
);
|
||||
|
||||
return showMeshSheet<void>(
|
||||
context,
|
||||
builder: (sheetContext) {
|
||||
final sheetMedia = MediaQuery.of(sheetContext);
|
||||
final screenHeight = math.min(
|
||||
callerMedia.size.height,
|
||||
sheetMedia.size.height,
|
||||
);
|
||||
final maxSheetHeight = math.max(
|
||||
0.0,
|
||||
math.min(
|
||||
screenHeight * 0.82 - bottomSafeInset,
|
||||
screenHeight - safeTop - math.max(callerBottom, navBottom),
|
||||
),
|
||||
);
|
||||
return MediaQuery(
|
||||
data: sheetMedia.copyWith(textScaler: callerMedia.textScaler),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(bottom: extraBottom),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: maxSheetHeight),
|
||||
child: _MessageTranslationSheet(
|
||||
enabled: enabled,
|
||||
selectedLanguageCode: selectedLanguageCode,
|
||||
onEnabledChanged: onEnabledChanged,
|
||||
onLanguageSelected: onLanguageSelected,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,6 +115,8 @@ class _MessageTranslationSheet extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MessageTranslationSheetState extends State<_MessageTranslationSheet> {
|
||||
final GlobalKey _switchKey = GlobalKey();
|
||||
final GlobalKey _searchKey = GlobalKey();
|
||||
late final TextEditingController _searchController;
|
||||
late bool _localEnabled;
|
||||
late String? _localSelectedLanguageCode;
|
||||
@@ -98,95 +146,166 @@ class _MessageTranslationSheetState extends State<_MessageTranslationSheet> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildSwitchTile(BuildContext context) {
|
||||
return KeyedSubtree(
|
||||
key: _switchKey,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(context.l10n.translation_translateBeforeSending),
|
||||
subtitle: Text(
|
||||
_localEnabled
|
||||
? context.l10n.translation_composerEnabledHint
|
||||
: context.l10n.translation_composerDisabledHint,
|
||||
),
|
||||
value: _localEnabled,
|
||||
onChanged: (value) {
|
||||
setState(() => _localEnabled = value);
|
||||
widget.onEnabledChanged(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchField(BuildContext context) {
|
||||
return KeyedSubtree(
|
||||
key: _searchKey,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
onChanged: _updateFilter,
|
||||
decoration: InputDecoration(
|
||||
labelText: context.l10n.translation_targetLanguage,
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLanguageTile(BuildContext context, int index) {
|
||||
if (index == 0) {
|
||||
final selected = _localSelectedLanguageCode == null;
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
leading: Icon(
|
||||
selected ? Icons.radio_button_checked : Icons.radio_button_unchecked,
|
||||
),
|
||||
title: Text(context.l10n.translation_useAppLanguage),
|
||||
onTap: () {
|
||||
setState(() => _localSelectedLanguageCode = null);
|
||||
widget.onLanguageSelected(null);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
final option = _filtered[index - 1];
|
||||
final selected = option.code == _localSelectedLanguageCode;
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
leading: Icon(
|
||||
selected ? Icons.radio_button_checked : Icons.radio_button_unchecked,
|
||||
),
|
||||
title: Text(option.label),
|
||||
subtitle: Text(option.code.toUpperCase()),
|
||||
onTap: () {
|
||||
setState(() => _localSelectedLanguageCode = option.code);
|
||||
widget.onLanguageSelected(option.code);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 16,
|
||||
bottom: 16 + MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
child: Column(
|
||||
final header = BottomSheetHeader(
|
||||
title: context.l10n.translation_messageTranslation,
|
||||
);
|
||||
final switchTile = _buildSwitchTile(context);
|
||||
final searchField = _buildSearchField(context);
|
||||
final itemCount = _filtered.length + 1;
|
||||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final scaler = MediaQuery.textScalerOf(context);
|
||||
final narrow = constraints.maxWidth < 360;
|
||||
final minPinnedHeight = scaler.scale(narrow ? 360 : 300);
|
||||
|
||||
if (constraints.maxHeight < scaler.scale(150)) {
|
||||
return CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: header),
|
||||
SliverToBoxAdapter(child: switchTile),
|
||||
SliverToBoxAdapter(child: searchField),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
sliver: SliverList.list(
|
||||
children: [
|
||||
for (var i = 0; i < itemCount; i++)
|
||||
_buildLanguageTile(context, i),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
if (constraints.maxHeight < minPinnedHeight) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
header,
|
||||
Flexible(
|
||||
child: CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
keyboardDismissBehavior:
|
||||
ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: switchTile),
|
||||
SliverToBoxAdapter(child: searchField),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
sliver: SliverList.list(
|
||||
children: [
|
||||
for (var i = 0; i < itemCount; i++)
|
||||
_buildLanguageTile(context, i),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
context.l10n.translation_messageTranslation,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(context.l10n.translation_translateBeforeSending),
|
||||
subtitle: Text(
|
||||
_localEnabled
|
||||
? context.l10n.translation_composerEnabledHint
|
||||
: context.l10n.translation_composerDisabledHint,
|
||||
),
|
||||
value: _localEnabled,
|
||||
onChanged: (value) {
|
||||
setState(() => _localEnabled = value);
|
||||
widget.onEnabledChanged(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: _searchController,
|
||||
onChanged: _updateFilter,
|
||||
decoration: InputDecoration(
|
||||
labelText: context.l10n.translation_targetLanguage,
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
header,
|
||||
switchTile,
|
||||
searchField,
|
||||
Flexible(
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: _filtered.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
final selected = _localSelectedLanguageCode == null;
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(
|
||||
selected
|
||||
? Icons.radio_button_checked
|
||||
: Icons.radio_button_unchecked,
|
||||
),
|
||||
title: Text(context.l10n.translation_useAppLanguage),
|
||||
onTap: () {
|
||||
setState(() => _localSelectedLanguageCode = null);
|
||||
widget.onLanguageSelected(null);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
final option = _filtered[index - 1];
|
||||
final selected = option.code == _localSelectedLanguageCode;
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(
|
||||
selected
|
||||
? Icons.radio_button_checked
|
||||
: Icons.radio_button_unchecked,
|
||||
),
|
||||
title: Text(option.label),
|
||||
subtitle: Text(option.code.toUpperCase()),
|
||||
onTap: () {
|
||||
setState(() => _localSelectedLanguageCode = option.code);
|
||||
widget.onLanguageSelected(option.code);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
keyboardDismissBehavior:
|
||||
ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
itemCount: itemCount,
|
||||
itemBuilder: _buildLanguageTile,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user