You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fluffychat/lib/utils/matrix_sdk_extensions/ios_badge_client_extension....

20 lines
704 B
Dart

import 'package:flutter_app_badger/flutter_app_badger.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/utils/platform_infos.dart';
extension IosBadgeClientExtension on Client {
void updateIosBadge() {
if (!PlatformInfos.isIOS) return;
final unreadCount = rooms.where((room) => room.isUnreadOrInvited).length;
if (unreadCount == 0) {
FlutterAppBadger.removeBadge();
FlutterLocalNotificationsPlugin()
.cancelAll(); // Workaround for iOS not clearing notifications with fcm_shared_isolate
} else {
FlutterAppBadger.updateBadgeCount(unreadCount);
}
}
}