flutter_native_badge
Wrapper for native badge APIs on iOS and macOS. It allows you to change the badge of your app icon, by setting the count, showing red dot, clearing the badge and getting the current badge count.
It supports iOS and macOS for now. Other platforms are not supported yet.
Preview
Ios App | MacOs App |
---|---|
Usage
Before using any of the methods, you should check if the platform is supported. If not, the methods will throw an unsupported exception.
Each method will check if the permission is granted if you set the requestPermission
parameter to true. If not, it will not request the permission and the method may not work if the permission is not granted.
Import
import 'package:flutter_native_badge/flutter_native_badge.dart';
Check if the platform is supported
bool isSupported = await FlutterNativeBadge.isSupported();
Set badge count
FlutterNativeBadge.setBadgeCount(5);
Show red dot
FlutterNativeBadge.showRedDot();
Clear badge count
FlutterNativeBadge.clearBadgeCount();
Get badge count
int badgeCount = await FlutterNativeBadge.getBadgeCount();
For iOS: getBadgeCount
depends on deprecated API and could be unavailable in future iOS releases!
There aren't any replacements in iOS SDK.
If you use getBadgeCount
now, you had better to consider how to manage the count yourself.
Request permission
Each method has a requestPermission
parameter. If you set it to true, it will request the permission if it is not granted.
FlutterNativeBadge.setBadgeCount(5, requestPermission: true);
FlutterNativeBadge.showRedDot(requestPermission: true);
FlutterNativeBadge.clearBadgeCount(requestPermission: true);
int badgeCount = await FlutterNativeBadge.getBadgeCount(requestPermission: true);
Contributing
Contributions are welcome! Please follow the Flutter & Dart standard and make a PR.