From f8246338d8f916b3b08168263e8c61bd65118d4a Mon Sep 17 00:00:00 2001 From: Kima Date: Fri, 29 Mar 2024 00:01:46 +0100 Subject: [PATCH] app icon change progress but i'm tired bye --- lib/helpers/app_icon_helper.dart | 84 ++++++++++++++++++-------------- pubspec.yaml | 1 + 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/lib/helpers/app_icon_helper.dart b/lib/helpers/app_icon_helper.dart index 275b3ea..121a5ff 100644 --- a/lib/helpers/app_icon_helper.dart +++ b/lib/helpers/app_icon_helper.dart @@ -1,48 +1,60 @@ -import 'dart:io'; - import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; -import 'package:flutter_dynamic_icon/flutter_dynamic_icon.dart'; -import 'package:android_dynamic_icon/android_dynamic_icon.dart'; +import 'package:flutter_dynamic_icon_plus/flutter_dynamic_icon_plus.dart'; class AppIconHelper { - static const _channel = MethodChannel('app_icon'); + // static const _channel = MethodChannel('app_icon'); static Future setAppIcon(String iconName) async { - if (Platform.isIOS) { - // change icon on ios - try { - if (await FlutterDynamicIcon.supportsAlternateIcons) { - await _channel.invokeMethod('changeIcon', iconName); - // await FlutterDynamicIcon.setApplicationIconBadgeNumber(0); we don't need this rn, but we will - await FlutterDynamicIcon.setAlternateIconName(iconName); - } - } on PlatformException catch (e) { + try { + if (await FlutterDynamicIconPlus.supportsAlternateIcons) { + await FlutterDynamicIconPlus.setAlternateIconName("icon_new"); if (kDebugMode) { - print('Failed to change app icon: ${e.message}'); - } - } catch (e) { - if (kDebugMode) { - print('Ha nem megy, hat nem megy'); + print("successfully changed app icon"); } + return; } - } else if (Platform.isAndroid) { - // change icon on android - // ignore: no_leading_underscores_for_local_identifiers - final _androidDynamicIconPlugin = AndroidDynamicIcon(); - await _androidDynamicIconPlugin.changeIcon( - bundleId: 'hu.refilc.naplo', - isNewIcon: iconName != 'refilc_default' ? true : false, - iconName: iconName != 'refilc_default' ? iconName : '', - iconNames: [ - 'refilc_default', - 'refilc_overcomplicated', - 'refilc_concept', - 'refilc_pride', - ], - ); - } else { - // ha nem megy hát nem megy + } on PlatformException { + if (kDebugMode) { + print("failed to change icon"); + } + } catch (e) { + // ha nem megy hat nem megy } + // if (Platform.isIOS) { + // // change icon on ios + // try { + // if (await FlutterDynamicIcon.supportsAlternateIcons) { + // await _channel.invokeMethod('changeIcon', iconName); + // // await FlutterDynamicIcon.setApplicationIconBadgeNumber(0); we don't need this rn, but we will + // await FlutterDynamicIcon.setAlternateIconName(iconName); + // } + // } on PlatformException catch (e) { + // if (kDebugMode) { + // print('Failed to change app icon: ${e.message}'); + // } + // } catch (e) { + // if (kDebugMode) { + // print('Ha nem megy, hat nem megy'); + // } + // } + // } else if (Platform.isAndroid) { + // // change icon on android + // // ignore: no_leading_underscores_for_local_identifiers + // final _androidDynamicIconPlugin = AndroidDynamicIcon(); + // await _androidDynamicIconPlugin.changeIcon( + // bundleId: 'hu.refilc.naplo', + // isNewIcon: iconName != 'refilc_default' ? true : false, + // iconName: iconName != 'refilc_default' ? iconName : '', + // iconNames: [ + // 'refilc_default', + // 'refilc_overcomplicated', + // 'refilc_concept', + // 'refilc_pride', + // ], + // ); + // } else { + // // ha nem megy hát nem megy + // } } } diff --git a/pubspec.yaml b/pubspec.yaml index 57c789b..18c298b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: i18n_extension: ^11.0.12 http: ^1.2.0 fl_chart: ^0.45.1 + flutter_dynamic_icon_plus: ^1.1.2 dev_dependencies: flutter_lints: ^3.0.1