From 4390062563b8d26d00c69eeb0f625488a5477c2a Mon Sep 17 00:00:00 2001 From: thanhtunguet Date: Mon, 29 Dec 2025 16:05:05 +0700 Subject: [PATCH 1/2] Ignore web platform by default. --- lib/flutter_app_badge_control_method_channel.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/flutter_app_badge_control_method_channel.dart b/lib/flutter_app_badge_control_method_channel.dart index 726918b..84440be 100644 --- a/lib/flutter_app_badge_control_method_channel.dart +++ b/lib/flutter_app_badge_control_method_channel.dart @@ -12,6 +12,9 @@ class MethodChannelFlutterAppBadgeControl @override Future getPlatformVersion() async { + if (kIsWeb) { + return 'Web'; + } final version = await methodChannel.invokeMethod('getPlatformVersion'); return version; @@ -19,16 +22,28 @@ class MethodChannelFlutterAppBadgeControl @override Future updateBadgeCount(int count) async { + if (kIsWeb) { + // Web doesn't support app badge count + return; + } return await methodChannel.invokeMethod('updateBadgeCount', count); } @override Future removeBadge() async { + if (kIsWeb) { + // Web doesn't support app badge removal + return; + } return await methodChannel.invokeMethod('removeBadge'); } @override Future isAppBadgeSupported() async { + if (kIsWeb) { + // Web doesn't support app badges + return false; + } final isSupported = await methodChannel.invokeMethod('isAppBadgeSupported'); return isSupported ?? false; From d5543982f4e5fdc0ba530e9178dc7e50b4f6b545 Mon Sep 17 00:00:00 2001 From: thanhtunguet Date: Mon, 29 Dec 2025 16:05:22 +0700 Subject: [PATCH 2/2] add macos support --- .../FlutterAppBadgeControlPlugin.swift | 41 +++++++++++++++++++ macos/flutter_app_badge_control.podspec | 22 ++++++++++ pubspec.yaml | 2 + 3 files changed, 65 insertions(+) create mode 100644 macos/Classes/FlutterAppBadgeControlPlugin.swift create mode 100644 macos/flutter_app_badge_control.podspec diff --git a/macos/Classes/FlutterAppBadgeControlPlugin.swift b/macos/Classes/FlutterAppBadgeControlPlugin.swift new file mode 100644 index 0000000..4650e75 --- /dev/null +++ b/macos/Classes/FlutterAppBadgeControlPlugin.swift @@ -0,0 +1,41 @@ +import Cocoa +import FlutterMacOS + +public class FlutterAppBadgeControlPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "flutter_app_badge_control", binaryMessenger: registrar.messenger) + let instance = FlutterAppBadgeControlPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + switch call.method { + case "getPlatformVersion": + result("macOS " + ProcessInfo.processInfo.operatingSystemVersionString) + case "updateBadgeCount": + if let count = call.arguments as? Int { + updateBadgeCount(count: count) + result(nil) + } else { + result(FlutterError(code: "INVALID_ARGUMENT", message: "Invalid count value", details: nil)) + } + case "removeBadge": + updateBadgeCount(count: 0) + result(nil) + case "isAppBadgeSupported": + result(true) + default: + result(FlutterMethodNotImplemented) + } + } + + private func updateBadgeCount(count: Int) { + DispatchQueue.main.async { + if count > 0 { + NSApp.dockTile.badgeLabel = "\(count)" + } else { + NSApp.dockTile.badgeLabel = nil + } + } + } +} \ No newline at end of file diff --git a/macos/flutter_app_badge_control.podspec b/macos/flutter_app_badge_control.podspec new file mode 100644 index 0000000..a734eed --- /dev/null +++ b/macos/flutter_app_badge_control.podspec @@ -0,0 +1,22 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint flutter_app_badge_control.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'flutter_app_badge_control' + s.version = '0.0.1' + s.summary = 'A new Flutter plugin project.' + s.description = <<-DESC +A new Flutter plugin project. + DESC + s.homepage = 'http://example.com' + s.license = { :file => '../LICENSE' } + s.author = { 'Your Company' => 'email@example.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'FlutterMacOS' + + s.platform = :osx, '10.11' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + s.swift_version = '5.0' +end \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index d3f0fac..52429cf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,6 +39,8 @@ flutter: pluginClass: FlutterAppBadgeControlPlugin ios: pluginClass: FlutterAppBadgeControlPlugin + macos: + pluginClass: FlutterAppBadgeControlPlugin # To add assets to your plugin package, add an assets section, like this: # assets: