Rename existing reminder channel on start

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-10 17:56:27 +01:00
parent 957ddc7ddc
commit 0982565fdc
3 changed files with 32 additions and 1 deletions

View File

@ -24,6 +24,20 @@ class LocalNotificationsBackend implements NotificationBackend {
android: AndroidInitializationSettings('@mipmap/ic_launcher'),
);
await plugin.initialize(settings: settings);
// Re-create the channel so Android renames it if an install still shows
// the old "Meal reminders" label.
await plugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin
>()
?.createNotificationChannel(
const AndroidNotificationChannel(
_channelId,
_channelName,
importance: Importance.high,
),
);
}
/// Requests Android 13+'s runtime `POST_NOTIFICATIONS` permission.

View File

@ -2,7 +2,7 @@ name: diet_guard_app
description: "Companion phone app for diet_guard: log meals on the go."
publish_to: 'none'
version: 1.0.150+1
version: 1.0.151+1
environment:
sdk: ^3.12.2

View File

@ -34,6 +34,23 @@ void main() {
expect(log.where((c) => c.method == 'initialize'), hasLength(1));
});
test('init renames the reminder channel to the app name', () async {
final log = installFakeAndroidNotifications();
NotificationService.resetForTesting(
backend: LocalNotificationsBackend(FlutterLocalNotificationsPlugin()),
);
await NotificationService.init();
final createCall = log.firstWhere(
(c) => c.method == 'createNotificationChannel',
orElse: () => throw StateError('no createNotificationChannel call logged'),
);
final args = createCall.arguments as Map;
expect(args['id'], reminderChannelId);
expect(args['name'], 'DietGuard');
});
test('requestPermission delegates to the Android implementation', () async {
installFakeAndroidNotifications();
NotificationService.resetForTesting(