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
@@ -102,10 +102,11 @@ Access via **App Settings → Notifications**:
|
||||
|
||||
| Setting | Default | Description |
|
||||
|---|---|---|
|
||||
| Enable Notifications | On | Master toggle; requests OS permission when turned on |
|
||||
| Message Notifications | On | DM alerts (greyed out if master is off) |
|
||||
| Channel Message Notifications | On | Channel alerts (greyed out if master is off) |
|
||||
| Advertisement Notifications | On | New node alerts (greyed out if master is off) |
|
||||
| Enable Notifications | On | Master toggle (shows off if OS permission is denied); requests OS permission when turned on and reveals the options below |
|
||||
| Message Notifications | On | Direct message alerts (shown when notifications are enabled) |
|
||||
| Channel Message Notifications | On | Channel message alerts (shown when notifications are enabled) |
|
||||
| Advertisement Notifications | On | New node alerts (shown when notifications are enabled) |
|
||||
| Background Activity (Android) | — | Opens system battery optimization settings (shown when notifications are enabled) |
|
||||
|
||||
### Per-Channel Notification Modes
|
||||
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,498 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/screens/app_settings_screen.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/network_map/network_map_upload_service.dart';
|
||||
import 'package:meshcore_open/services/notification_service.dart';
|
||||
import 'package:meshcore_open/services/translation_service.dart';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/utils/platform_info.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_nav_tile.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||
import 'package:meshcore_open/widgets/settings_reveal.dart';
|
||||
|
||||
Future<AppSettingsService> _createSettingsService({
|
||||
bool notificationsEnabled = true,
|
||||
}) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
PrefsManager.reset();
|
||||
await PrefsManager.initialize();
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
if (!notificationsEnabled) {
|
||||
await settings.setNotificationsEnabled(false);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
Widget _buildSectionTestApp({
|
||||
required AppSettingsService settings,
|
||||
ThemeData? theme,
|
||||
double textScale = 1.0,
|
||||
Future<bool> Function()? hasPermission,
|
||||
Future<bool> Function()? requestPermission,
|
||||
}) {
|
||||
return ChangeNotifierProvider.value(
|
||||
value: settings,
|
||||
child: MaterialApp(
|
||||
theme: theme ?? MeshTheme.light(),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: child!,
|
||||
),
|
||||
home: Scaffold(
|
||||
body: MeshSettingsTileTheme(
|
||||
child: SingleChildScrollView(
|
||||
child: MeshCard(
|
||||
padding: EdgeInsets.zero,
|
||||
child: NotificationsSettingsSection(
|
||||
hasPermission: hasPermission,
|
||||
requestPermission: requestPermission,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
setUp(() {
|
||||
NotificationService().resetForTest();
|
||||
PlatformInfo.debugIsAndroidOverride = null;
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
NotificationService().resetForTest();
|
||||
PlatformInfo.debugIsAndroidOverride = null;
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'notificationsEnabled + OS permission granted shows switch ON, expanded SettingsReveal, and exact row order including Android Background Activity last',
|
||||
(tester) async {
|
||||
PlatformInfo.debugIsAndroidOverride = true;
|
||||
final settings = await _createSettingsService(notificationsEnabled: true);
|
||||
|
||||
await tester.pumpWidget(
|
||||
_buildSectionTestApp(
|
||||
settings: settings,
|
||||
hasPermission: () async => true,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(NotificationsSettingsSection));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
final enableTile = tester.widget<SwitchListTile>(
|
||||
find.widgetWithText(
|
||||
SwitchListTile,
|
||||
l10n.appSettings_enableNotifications,
|
||||
),
|
||||
);
|
||||
expect(enableTile.value, isTrue);
|
||||
expect(
|
||||
find.text(l10n.appSettings_enableNotificationsSubtitle),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
final reveal = tester.widget<SettingsReveal>(find.byType(SettingsReveal));
|
||||
expect(reveal.visible, isTrue);
|
||||
|
||||
final msgFinder = find.text(l10n.appSettings_messageNotifications);
|
||||
final channelFinder = find.text(
|
||||
l10n.appSettings_channelMessageNotifications,
|
||||
);
|
||||
final advertFinder = find.text(
|
||||
l10n.appSettings_advertisementNotifications,
|
||||
);
|
||||
final bgActivityFinder = find.text(l10n.appSettings_batteryOptimization);
|
||||
|
||||
expect(msgFinder, findsOneWidget);
|
||||
expect(channelFinder, findsOneWidget);
|
||||
expect(advertFinder, findsOneWidget);
|
||||
expect(bgActivityFinder, findsOneWidget);
|
||||
|
||||
final msgY = tester.getTopLeft(msgFinder).dy;
|
||||
final channelY = tester.getTopLeft(channelFinder).dy;
|
||||
final advertY = tester.getTopLeft(advertFinder).dy;
|
||||
final bgActivityY = tester.getTopLeft(bgActivityFinder).dy;
|
||||
|
||||
expect(msgY, lessThan(channelY));
|
||||
expect(channelY, lessThan(advertY));
|
||||
expect(advertY, lessThan(bgActivityY));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'notificationsEnabled + OS permission denied shows switch OFF, hides child toggles, shows denied subtitle, and requests permission on tap',
|
||||
(tester) async {
|
||||
PlatformInfo.debugIsAndroidOverride = true;
|
||||
final settings = await _createSettingsService(notificationsEnabled: true);
|
||||
var requestResult = false;
|
||||
var requestCalls = 0;
|
||||
|
||||
await tester.pumpWidget(
|
||||
_buildSectionTestApp(
|
||||
settings: settings,
|
||||
hasPermission: () async => false,
|
||||
requestPermission: () async {
|
||||
requestCalls++;
|
||||
return requestResult;
|
||||
},
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(NotificationsSettingsSection));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
SwitchListTile enableTile() => tester.widget<SwitchListTile>(
|
||||
find.widgetWithText(
|
||||
SwitchListTile,
|
||||
l10n.appSettings_enableNotifications,
|
||||
),
|
||||
);
|
||||
|
||||
// Even though settings.notificationsEnabled is true, switch is OFF when OS permission is denied.
|
||||
expect(settings.settings.notificationsEnabled, isTrue);
|
||||
expect(enableTile().value, isFalse);
|
||||
expect(
|
||||
find.text(l10n.appSettings_notificationPermissionDenied),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsNothing);
|
||||
expect(
|
||||
find.text(l10n.appSettings_channelMessageNotifications),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.text(l10n.appSettings_advertisementNotifications),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_batteryOptimization), findsNothing);
|
||||
// No stray Divider when collapsed.
|
||||
expect(find.byType(Divider), findsNothing);
|
||||
|
||||
// Tapping switch while permission request is denied keeps it OFF and shows snackbar.
|
||||
await tester.tap(find.text(l10n.appSettings_enableNotifications));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(requestCalls, 1);
|
||||
expect(enableTile().value, isFalse);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsNothing);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(SnackBar),
|
||||
matching: find.text(l10n.appSettings_notificationPermissionDenied),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Now grant permission on the next tap: switch turns ON, snackbar appears, and children expand.
|
||||
requestResult = true;
|
||||
await tester.tap(find.text(l10n.appSettings_enableNotifications));
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(requestCalls, 2);
|
||||
expect(enableTile().value, isTrue);
|
||||
expect(settings.settings.notificationsEnabled, isTrue);
|
||||
expect(
|
||||
find.text(l10n.appSettings_enableNotificationsSubtitle),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(SnackBar),
|
||||
matching: find.text(l10n.appSettings_notificationsEnabled),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsOneWidget);
|
||||
expect(
|
||||
find.text(l10n.appSettings_channelMessageNotifications),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(l10n.appSettings_advertisementNotifications),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_batteryOptimization), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('does not flash ON while async OS permission check is in flight', (
|
||||
tester,
|
||||
) async {
|
||||
final settings = await _createSettingsService(notificationsEnabled: true);
|
||||
final completer = Completer<bool>();
|
||||
|
||||
await tester.pumpWidget(
|
||||
_buildSectionTestApp(
|
||||
settings: settings,
|
||||
hasPermission: () => completer.future,
|
||||
),
|
||||
);
|
||||
|
||||
final context = tester.element(find.byType(NotificationsSettingsSection));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
// While async permission check is in flight, switch is OFF and children are hidden,
|
||||
// and the normal subtitle is shown rather than flashing an error prematurely.
|
||||
final initialTile = tester.widget<SwitchListTile>(
|
||||
find.widgetWithText(SwitchListTile, l10n.appSettings_enableNotifications),
|
||||
);
|
||||
expect(initialTile.value, isFalse);
|
||||
expect(
|
||||
find.text(l10n.appSettings_enableNotificationsSubtitle),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsNothing);
|
||||
|
||||
completer.complete(false);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final settledTile = tester.widget<SwitchListTile>(
|
||||
find.widgetWithText(SwitchListTile, l10n.appSettings_enableNotifications),
|
||||
);
|
||||
expect(settledTile.value, isFalse);
|
||||
expect(
|
||||
find.text(l10n.appSettings_notificationPermissionDenied),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'toggling OFF -> ON collapses children out of tree and expands them back',
|
||||
(tester) async {
|
||||
final settings = await _createSettingsService(notificationsEnabled: true);
|
||||
|
||||
await tester.pumpWidget(
|
||||
_buildSectionTestApp(
|
||||
settings: settings,
|
||||
hasPermission: () async => true,
|
||||
requestPermission: () async => true,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(NotificationsSettingsSection));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsOneWidget);
|
||||
|
||||
// Toggle OFF
|
||||
await tester.tap(find.text(l10n.appSettings_enableNotifications));
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(settings.settings.notificationsEnabled, isFalse);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsNothing);
|
||||
expect(
|
||||
find.text(l10n.appSettings_channelMessageNotifications),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
find.text(l10n.appSettings_advertisementNotifications),
|
||||
findsNothing,
|
||||
);
|
||||
expect(find.byType(Divider), findsNothing);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(SnackBar),
|
||||
matching: find.text(l10n.appSettings_notificationsDisabled),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// Toggle back ON
|
||||
await tester.tap(find.text(l10n.appSettings_enableNotifications));
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(settings.settings.notificationsEnabled, isTrue);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsOneWidget);
|
||||
expect(
|
||||
find.text(l10n.appSettings_channelMessageNotifications),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
find.text(l10n.appSettings_advertisementNotifications),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'AppLifecycleState.resumed re-checks OS permission for revoke and grant',
|
||||
(tester) async {
|
||||
final settings = await _createSettingsService(notificationsEnabled: true);
|
||||
var osPermissionGranted = true;
|
||||
|
||||
await tester.pumpWidget(
|
||||
_buildSectionTestApp(
|
||||
settings: settings,
|
||||
hasPermission: () async => osPermissionGranted,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(NotificationsSettingsSection));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
SwitchListTile enableTile() => tester.widget<SwitchListTile>(
|
||||
find.widgetWithText(
|
||||
SwitchListTile,
|
||||
l10n.appSettings_enableNotifications,
|
||||
),
|
||||
);
|
||||
|
||||
expect(enableTile().value, isTrue);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsOneWidget);
|
||||
|
||||
// User revokes permission in OS settings and resumes app.
|
||||
osPermissionGranted = false;
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(enableTile().value, isFalse);
|
||||
expect(
|
||||
find.text(l10n.appSettings_notificationPermissionDenied),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsNothing);
|
||||
|
||||
// User grants permission in OS settings and resumes app.
|
||||
osPermissionGranted = true;
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pump();
|
||||
await tester.pump(RevealOnEnable.duration);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(enableTile().value, isTrue);
|
||||
expect(
|
||||
find.text(l10n.appSettings_enableNotificationsSubtitle),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'AppSettingsScreen integrates NotificationService permission hook',
|
||||
(tester) async {
|
||||
final settings = await _createSettingsService(notificationsEnabled: true);
|
||||
NotificationService().permissionCheckerForTest = () async => false;
|
||||
|
||||
tester.view.physicalSize = const Size(800, 4000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final connector = MeshCoreConnector();
|
||||
final translation = TranslationService(settings);
|
||||
final uploads = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
);
|
||||
addTearDown(connector.dispose);
|
||||
addTearDown(translation.dispose);
|
||||
addTearDown(uploads.dispose);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: settings),
|
||||
ChangeNotifierProvider.value(value: connector),
|
||||
ChangeNotifierProvider.value(value: translation),
|
||||
ChangeNotifierProvider.value(value: uploads),
|
||||
],
|
||||
child: MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const AppSettingsScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final context = tester.element(find.byType(AppSettingsScreen));
|
||||
final l10n = AppLocalizations.of(context);
|
||||
|
||||
final enableTile = tester.widget<SwitchListTile>(
|
||||
find.widgetWithText(
|
||||
SwitchListTile,
|
||||
l10n.appSettings_enableNotifications,
|
||||
),
|
||||
);
|
||||
expect(enableTile.value, isFalse);
|
||||
expect(
|
||||
find.text(l10n.appSettings_notificationPermissionDenied),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(l10n.appSettings_messageNotifications), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
for (final isDark in [false, true]) {
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
for (final granted in [true, false]) {
|
||||
testWidgets(
|
||||
'NotificationsSettingsSection fits 320dp at ${scale}x in ${isDark ? "dark" : "light"} theme when permission=${granted ? "granted" : "denied"}',
|
||||
(tester) async {
|
||||
PlatformInfo.debugIsAndroidOverride = true;
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final settings = await _createSettingsService(
|
||||
notificationsEnabled: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
_buildSectionTestApp(
|
||||
settings: settings,
|
||||
theme: isDark ? MeshTheme.dark() : MeshTheme.light(),
|
||||
textScale: scale,
|
||||
hasPermission: () async => granted,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
// Verify 48dp minimum touch target height on all rendered tiles.
|
||||
final tiles = find.byType(ListTile);
|
||||
expect(tiles, findsWidgets);
|
||||
for (final element in tiles.evaluate()) {
|
||||
final size = tester.getSize(find.byWidget(element.widget));
|
||||
expect(size.height, greaterThanOrEqualTo(48));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/services/notification_service.dart';
|
||||
|
||||
class _NoopNotificationsPlatform extends FlutterLocalNotificationsPlatform {}
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
const channel = MethodChannel('dexterous.com/flutter/local_notifications');
|
||||
final service = NotificationService();
|
||||
|
||||
setUp(() {
|
||||
service.resetForTest();
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, null);
|
||||
FlutterLocalNotificationsPlatform.instance = _NoopNotificationsPlatform();
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
service.resetForTest();
|
||||
});
|
||||
|
||||
group('NotificationService.hasNotificationPermission', () {
|
||||
test('queries Android areNotificationsEnabled and updates cache', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
AndroidFlutterLocalNotificationsPlugin.registerWith();
|
||||
|
||||
bool? androidEnabled = true;
|
||||
var checkCalls = 0;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
if (call.method == 'initialize') return true;
|
||||
if (call.method == 'areNotificationsEnabled') {
|
||||
checkCalls++;
|
||||
return androidEnabled;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
expect(await service.hasNotificationPermission(), isTrue);
|
||||
expect(service.canNotifyCacheForTest, isTrue);
|
||||
expect(checkCalls, 1);
|
||||
|
||||
// Subsequent ensureCanNotify uses the cached grant without re-querying.
|
||||
expect(await service.ensureCanNotifyForTest(), isTrue);
|
||||
expect(checkCalls, 1);
|
||||
|
||||
// Revoking OS permission invalidates the cached true on the next live check.
|
||||
androidEnabled = false;
|
||||
expect(await service.hasNotificationPermission(), isFalse);
|
||||
expect(service.canNotifyCacheForTest, isNull);
|
||||
expect(checkCalls, 2);
|
||||
|
||||
// _ensureCanNotify now re-queries and returns false instead of stale true.
|
||||
expect(await service.ensureCanNotifyForTest(), isFalse);
|
||||
expect(checkCalls, 3);
|
||||
|
||||
// Null response from channel is treated as false.
|
||||
androidEnabled = null;
|
||||
expect(await service.hasNotificationPermission(), isFalse);
|
||||
expect(service.canNotifyCacheForTest, isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'queries iOS checkPermissions and invalidates cache when revoked',
|
||||
() async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
|
||||
IOSFlutterLocalNotificationsPlugin.registerWith();
|
||||
|
||||
Map<String, Object?>? permissionsResponse = {
|
||||
'isEnabled': true,
|
||||
'isAlertEnabled': true,
|
||||
'isBadgeEnabled': true,
|
||||
'isSoundEnabled': true,
|
||||
'isProvisionalEnabled': false,
|
||||
'isCriticalEnabled': false,
|
||||
'isProvidesAppNotificationSettingsEnabled': false,
|
||||
'isCarPlayEnabled': false,
|
||||
};
|
||||
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
if (call.method == 'initialize') return true;
|
||||
if (call.method == 'checkPermissions') return permissionsResponse;
|
||||
return null;
|
||||
});
|
||||
|
||||
expect(await service.hasNotificationPermission(), isTrue);
|
||||
expect(service.canNotifyCacheForTest, isTrue);
|
||||
expect(await service.ensureCanNotifyForTest(), isTrue);
|
||||
|
||||
// Provisional permission also counts as granted.
|
||||
permissionsResponse = {
|
||||
'isEnabled': false,
|
||||
'isAlertEnabled': false,
|
||||
'isBadgeEnabled': false,
|
||||
'isSoundEnabled': false,
|
||||
'isProvisionalEnabled': true,
|
||||
};
|
||||
expect(await service.hasNotificationPermission(), isTrue);
|
||||
expect(service.canNotifyCacheForTest, isTrue);
|
||||
|
||||
// Denied in iOS Settings clears the cached grant.
|
||||
permissionsResponse = {
|
||||
'isEnabled': false,
|
||||
'isAlertEnabled': false,
|
||||
'isBadgeEnabled': false,
|
||||
'isSoundEnabled': false,
|
||||
'isProvisionalEnabled': false,
|
||||
};
|
||||
expect(await service.hasNotificationPermission(), isFalse);
|
||||
expect(service.canNotifyCacheForTest, isNull);
|
||||
expect(await service.ensureCanNotifyForTest(), isFalse);
|
||||
|
||||
permissionsResponse = null;
|
||||
expect(await service.hasNotificationPermission(), isFalse);
|
||||
},
|
||||
);
|
||||
|
||||
test('queries macOS checkPermissions and updates cache', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
|
||||
MacOSFlutterLocalNotificationsPlugin.registerWith();
|
||||
|
||||
Map<String, Object?>? permissionsResponse = {
|
||||
'isEnabled': true,
|
||||
'isAlertEnabled': true,
|
||||
'isBadgeEnabled': true,
|
||||
'isSoundEnabled': true,
|
||||
};
|
||||
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
if (call.method == 'initialize') return true;
|
||||
if (call.method == 'checkPermissions') return permissionsResponse;
|
||||
return null;
|
||||
});
|
||||
|
||||
expect(await service.hasNotificationPermission(), isTrue);
|
||||
expect(service.canNotifyCacheForTest, isTrue);
|
||||
|
||||
permissionsResponse = {
|
||||
'isEnabled': false,
|
||||
'isAlertEnabled': false,
|
||||
'isBadgeEnabled': false,
|
||||
'isSoundEnabled': false,
|
||||
};
|
||||
expect(await service.hasNotificationPermission(), isFalse);
|
||||
expect(service.canNotifyCacheForTest, isNull);
|
||||
});
|
||||
|
||||
test(
|
||||
'returns true on desktop platforms without an OS permission gate',
|
||||
() async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
FlutterLocalNotificationsPlatform.instance =
|
||||
_NoopNotificationsPlatform();
|
||||
|
||||
expect(await service.hasNotificationPermission(), isTrue);
|
||||
expect(service.canNotifyCacheForTest, isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test('requestPermissions updates and clears canNotify cache', () async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
AndroidFlutterLocalNotificationsPlugin.registerWith();
|
||||
|
||||
var grantResult = true;
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(channel, (call) async {
|
||||
if (call.method == 'initialize') return true;
|
||||
if (call.method == 'requestNotificationsPermission') {
|
||||
return grantResult;
|
||||
}
|
||||
if (call.method == 'areNotificationsEnabled') {
|
||||
return grantResult;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
expect(await service.requestPermissions(), isTrue);
|
||||
expect(service.canNotifyCacheForTest, isTrue);
|
||||
|
||||
grantResult = false;
|
||||
expect(await service.requestPermissions(), isFalse);
|
||||
expect(service.canNotifyCacheForTest, isNull);
|
||||
expect(await service.ensureCanNotifyForTest(), isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -65,6 +65,7 @@ Widget _app(
|
||||
Widget? replyPreview,
|
||||
bool disableAnimations = false,
|
||||
Brightness brightness = Brightness.light,
|
||||
List<ChatComposerAction>? actions,
|
||||
}) {
|
||||
final composer = ChatComposer(
|
||||
controller: h.controller,
|
||||
@@ -72,13 +73,15 @@ Widget _app(
|
||||
maxBytes: maxBytes,
|
||||
onSend: () => h.sends++,
|
||||
sendTooltip: _l10n.chat_sendMessage,
|
||||
actionsBuilder: () => [
|
||||
ChatComposerAction(
|
||||
id: 'gif',
|
||||
icon: Icons.gif_box,
|
||||
label: _l10n.chat_sendGif,
|
||||
),
|
||||
],
|
||||
actionsBuilder: () =>
|
||||
actions ??
|
||||
[
|
||||
ChatComposerAction(
|
||||
id: 'gif',
|
||||
icon: Icons.gif_box,
|
||||
label: _l10n.chat_sendGif,
|
||||
),
|
||||
],
|
||||
onAction: h.actions.add,
|
||||
replyPreview: replyPreview,
|
||||
);
|
||||
@@ -119,6 +122,7 @@ Widget _app(
|
||||
|
||||
Finder get _plus => find.byTooltip(_l10n.chat_selectSendAction);
|
||||
Finder get _send => find.byTooltip(_l10n.chat_sendMessage);
|
||||
Finder get _menu => find.byKey(ChatComposer.actionMenuKey);
|
||||
Finder get _bubble => find.byKey(ChatComposer.bubbleKey);
|
||||
|
||||
Future<void> _type(WidgetTester tester, String text) async {
|
||||
@@ -380,6 +384,180 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('+ menu opens above the button and grows upward from it', (
|
||||
tester,
|
||||
) async {
|
||||
final h = await _harness(tester);
|
||||
await tester.pumpWidget(_app(h));
|
||||
await tester.pumpAndSettle();
|
||||
final plusTop = tester.getTopLeft(_plus).dy;
|
||||
final plusRight = tester.getTopRight(_plus).dx;
|
||||
|
||||
await tester.tap(_plus);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
final early = tester.getRect(_menu);
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
final later = tester.getRect(_menu);
|
||||
expect(later.top, lessThan(early.top));
|
||||
expect(later.bottom, closeTo(early.bottom, 0.01));
|
||||
expect(later.height, greaterThan(early.height));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
final open = tester.getRect(_menu);
|
||||
expect(open.bottom, closeTo(early.bottom, 0.01));
|
||||
expect(open.bottom, lessThanOrEqualTo(plusTop));
|
||||
// Trailing edges line up (the tap target is a little wider than the
|
||||
// visible button).
|
||||
expect(open.right, closeTo(plusRight, 3));
|
||||
expect(open.height, greaterThanOrEqualTo(kMinInteractiveDimension));
|
||||
// The card hugs a short label instead of filling the width cap.
|
||||
expect(open.width, lessThan(280));
|
||||
|
||||
await tester.tapAt(const Offset(5, 5));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
final closing = tester.getRect(_menu);
|
||||
expect(closing.bottom, closeTo(open.bottom, 0.01));
|
||||
expect(closing.height, lessThan(open.height));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_menu, findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('+ menu opens at once with animations disabled', (tester) async {
|
||||
final h = await _harness(tester);
|
||||
await tester.pumpWidget(_app(h, disableAnimations: true));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_plus);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(find.text(_l10n.chat_sendGif), findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(_menu).height,
|
||||
greaterThanOrEqualTo(kMinInteractiveDimension),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(_menu).bottom,
|
||||
lessThanOrEqualTo(tester.getTopLeft(_plus).dy),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('+ menu keeps focus on the text field', (tester) async {
|
||||
final h = await _harness(tester);
|
||||
await tester.pumpWidget(_app(h));
|
||||
await tester.pumpAndSettle();
|
||||
h.focusNode.requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
expect(h.focusNode.hasFocus, isTrue);
|
||||
|
||||
await tester.tap(_plus);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(_l10n.chat_sendGif), findsOneWidget);
|
||||
expect(h.focusNode.hasFocus, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('tapping outside the + menu closes it without an action', (
|
||||
tester,
|
||||
) async {
|
||||
final h = await _harness(tester);
|
||||
await tester.pumpWidget(_app(h));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_plus);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_menu, findsOneWidget);
|
||||
|
||||
await tester.tapAt(const Offset(5, 5));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_menu, findsNothing);
|
||||
expect(h.actions, isEmpty);
|
||||
});
|
||||
|
||||
for (final scale in [1.3, 2.0]) {
|
||||
testWidgets('+ menu stays above the button at 320dp, ${scale}x text', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 568);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.textScaleFactorTestValue = scale;
|
||||
addTearDown(tester.view.reset);
|
||||
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
||||
final h = await _harness(tester);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
h,
|
||||
actions: [
|
||||
for (var i = 0; i < 4; i++)
|
||||
ChatComposerAction(
|
||||
id: 'a$i',
|
||||
icon: Icons.gif_box,
|
||||
label: 'A rather long action label number $i for the menu',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_plus);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final menu = tester.getRect(_menu);
|
||||
expect(menu.bottom, lessThanOrEqualTo(tester.getTopLeft(_plus).dy));
|
||||
expect(menu.left, greaterThanOrEqualTo(0));
|
||||
expect(menu.right, lessThanOrEqualTo(320));
|
||||
expect(menu.top, greaterThanOrEqualTo(0));
|
||||
|
||||
await tester.tap(find.textContaining('number 3'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(h.actions, ['a3']);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('+ menu re-clamps into the viewport when it shrinks while open', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(600, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final h = await _harness(tester);
|
||||
await tester.pumpWidget(
|
||||
_app(
|
||||
h,
|
||||
actions: [
|
||||
for (var i = 0; i < 6; i++)
|
||||
ChatComposerAction(
|
||||
id: 'a$i',
|
||||
icon: Icons.gif_box,
|
||||
label: 'A rather long action label number $i for the menu',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(_plus);
|
||||
await tester.pumpAndSettle();
|
||||
final before = tester.getRect(_menu);
|
||||
expect(find.textContaining('number 5'), findsOneWidget);
|
||||
|
||||
tester.view.physicalSize = const Size(240, 320);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
final after = tester.getRect(_menu);
|
||||
expect(after.width, lessThan(before.width));
|
||||
expect(after.height, lessThan(before.height));
|
||||
expect(after.left, greaterThanOrEqualTo(0));
|
||||
expect(after.right, lessThanOrEqualTo(240));
|
||||
expect(after.top, greaterThanOrEqualTo(0));
|
||||
expect(after.bottom, lessThanOrEqualTo(tester.getTopLeft(_plus).dy));
|
||||
|
||||
await tester.drag(
|
||||
find.descendant(of: _menu, matching: find.byType(Scrollable)),
|
||||
const Offset(0, -1000),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.textContaining('number 5'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(h.actions, ['a5']);
|
||||
});
|
||||
|
||||
testWidgets('panel is solid without a chat background and transparent '
|
||||
'over one', (tester) async {
|
||||
final h = await _harness(tester);
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations_en.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||
import 'package:meshcore_open/widgets/message_translation_button.dart';
|
||||
|
||||
final _l10n = AppLocalizationsEn();
|
||||
|
||||
Future<void> _openSheet(
|
||||
WidgetTester tester, {
|
||||
Size size = const Size(400, 800),
|
||||
EdgeInsets padding = const EdgeInsets.only(top: 48, bottom: 34),
|
||||
EdgeInsets viewPadding = const EdgeInsets.only(top: 48, bottom: 34),
|
||||
EdgeInsets viewInsets = EdgeInsets.zero,
|
||||
double textScale = 1.0,
|
||||
bool initialEnabled = false,
|
||||
String? initialLanguageCode,
|
||||
ValueChanged<bool>? onEnabledChanged,
|
||||
ValueChanged<String?>? onLanguageSelected,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
tester.view.padding = FakeViewPadding(
|
||||
left: padding.left,
|
||||
top: padding.top,
|
||||
right: padding.right,
|
||||
bottom: padding.bottom,
|
||||
);
|
||||
tester.view.viewPadding = FakeViewPadding(
|
||||
left: viewPadding.left,
|
||||
top: viewPadding.top,
|
||||
right: viewPadding.right,
|
||||
bottom: viewPadding.bottom,
|
||||
);
|
||||
tester.view.viewInsets = FakeViewPadding(
|
||||
left: viewInsets.left,
|
||||
top: viewInsets.top,
|
||||
right: viewInsets.right,
|
||||
bottom: viewInsets.bottom,
|
||||
);
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
addTearDown(tester.view.resetPadding);
|
||||
addTearDown(tester.view.resetViewPadding);
|
||||
addTearDown(tester.view.resetViewInsets);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: MeshTheme.light(),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
builder: (context, child) {
|
||||
final media = MediaQuery.of(context);
|
||||
return MediaQuery(
|
||||
data: media.copyWith(
|
||||
size: size,
|
||||
padding: padding,
|
||||
viewPadding: viewPadding,
|
||||
viewInsets: viewInsets,
|
||||
textScaler: TextScaler.linear(textScale),
|
||||
),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: Center(
|
||||
child: MessageTranslationButton(
|
||||
enabled: initialEnabled,
|
||||
languageCode: initialLanguageCode,
|
||||
onPressed: () => showMessageTranslationSheet(
|
||||
context: context,
|
||||
enabled: initialEnabled,
|
||||
selectedLanguageCode: initialLanguageCode,
|
||||
onEnabledChanged: onEnabledChanged ?? (_) {},
|
||||
onLanguageSelected: onLanguageSelected ?? (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byType(MessageTranslationButton));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'sheet respects top safe area, caps height at <= 85%, and shrinks when filtered',
|
||||
(tester) async {
|
||||
const screenSize = Size(400, 800);
|
||||
await _openSheet(
|
||||
tester,
|
||||
size: screenSize,
|
||||
padding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||
viewPadding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||
);
|
||||
|
||||
expect(find.byType(BottomSheetHeader), findsOneWidget);
|
||||
expect(find.text(_l10n.translation_messageTranslation), findsOneWidget);
|
||||
|
||||
final sheetFinder = find.byType(BottomSheet);
|
||||
final sheetRect = tester.getRect(sheetFinder);
|
||||
final titleTop = tester
|
||||
.getTopLeft(find.text(_l10n.translation_messageTranslation))
|
||||
.dy;
|
||||
|
||||
// Top edge must stay well below the 48px Android status bar inset.
|
||||
expect(sheetRect.top, greaterThan(48.0));
|
||||
expect(sheetRect.top, greaterThanOrEqualTo(screenSize.height * 0.15));
|
||||
expect(sheetRect.height, lessThanOrEqualTo(screenSize.height * 0.85));
|
||||
expect(titleTop - sheetRect.top, inInclusiveRange(16.0, 36.0));
|
||||
|
||||
final unfilteredHeight = sheetRect.height;
|
||||
|
||||
// Filtering down to a single language shrinks the sheet naturally.
|
||||
await tester.enterText(find.byType(TextField), 'Spanish');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final filteredRect = tester.getRect(sheetFinder);
|
||||
expect(filteredRect.height, lessThan(unfilteredHeight));
|
||||
expect(filteredRect.top, greaterThan(sheetRect.top));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'toggling switch, filtering languages, and selecting target or app language works',
|
||||
(tester) async {
|
||||
bool? latestEnabled;
|
||||
String? latestLanguage = 'fr';
|
||||
|
||||
await _openSheet(
|
||||
tester,
|
||||
initialEnabled: false,
|
||||
initialLanguageCode: latestLanguage,
|
||||
onEnabledChanged: (value) => latestEnabled = value,
|
||||
onLanguageSelected: (code) => latestLanguage = code,
|
||||
);
|
||||
|
||||
expect(find.text(_l10n.translation_composerDisabledHint), findsOneWidget);
|
||||
|
||||
await tester.tap(
|
||||
find.widgetWithText(
|
||||
SwitchListTile,
|
||||
_l10n.translation_translateBeforeSending,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(latestEnabled, isTrue);
|
||||
expect(find.text(_l10n.translation_composerEnabledHint), findsOneWidget);
|
||||
|
||||
// Filter by language name and select Spanish ('es').
|
||||
await tester.enterText(find.byType(TextField), 'Spanish');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.widgetWithText(ListTile, 'Spanish'), findsOneWidget);
|
||||
expect(find.widgetWithText(ListTile, 'German'), findsNothing);
|
||||
|
||||
await tester.tap(find.widgetWithText(ListTile, 'Spanish'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(latestLanguage, 'es');
|
||||
expect(find.byType(BottomSheet), findsNothing);
|
||||
|
||||
// Re-open and select "Use app language" (null).
|
||||
await tester.tap(find.byType(MessageTranslationButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(
|
||||
find.widgetWithText(ListTile, _l10n.translation_useAppLanguage),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(latestLanguage, isNull);
|
||||
expect(find.byType(BottomSheet), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'avoids layout overflow at 320dp width with 1.3x and 2.0x text scale and keyboard insets',
|
||||
(tester) async {
|
||||
for (final textScale in [1.0, 1.3, 2.0]) {
|
||||
for (final keyboardInset in [0.0, 300.0]) {
|
||||
bool? toggled;
|
||||
String? chosenLanguage;
|
||||
|
||||
await _openSheet(
|
||||
tester,
|
||||
size: const Size(320, 568),
|
||||
padding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||
viewPadding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||
viewInsets: EdgeInsets.only(bottom: keyboardInset),
|
||||
textScale: textScale,
|
||||
onEnabledChanged: (value) => toggled = value,
|
||||
onLanguageSelected: (code) => chosenLanguage = code,
|
||||
);
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
final sheetRect = tester.getRect(find.byType(BottomSheet));
|
||||
expect(sheetRect.top, greaterThanOrEqualTo(48.0));
|
||||
|
||||
await Scrollable.ensureVisible(
|
||||
tester.element(find.byType(Switch)),
|
||||
alignment: 0.5,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(Switch));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(toggled, isTrue);
|
||||
|
||||
await Scrollable.ensureVisible(
|
||||
tester.element(find.byType(TextField)),
|
||||
alignment: 0.5,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextField), 'de');
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
final germanTile = find.widgetWithText(
|
||||
ListTile,
|
||||
'German',
|
||||
skipOffstage: false,
|
||||
);
|
||||
await Scrollable.ensureVisible(
|
||||
tester.element(germanTile),
|
||||
alignment: 0.5,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(germanTile);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(chosenLanguage, 'de');
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user