initialize method
Future<bool>
initialize(
- String? defaultIcon,
- List<
NotificationChannel> channels, { - List<
NotificationChannelGroup> ? channelGroups, - bool debug = false,
override
INITIALIZING METHODS *********************************************
Initializes the plugin, creating a default icon and the initial channels. Only needs
to be called at main.dart once.
OBS: defaultIcon needs to be a Resource media type
OBS 2: channels are updated if they already exists
Implementation
@override
Future<bool> initialize(
String? defaultIcon, List<NotificationChannel> channels,
{List<NotificationChannelGroup>? channelGroups,
bool debug = false}) async {
WidgetsFlutterBinding.ensureInitialized();
methodChannel.setMethodCallHandler(_handleMethod);
List<dynamic> serializedChannels = [];
for (NotificationChannel channel in channels) {
serializedChannels.add(channel.toMap());
}
List<dynamic> serializedChannelGroups = [];
if (channelGroups != null) {
for (NotificationChannelGroup channelGroup in channelGroups) {
serializedChannelGroups.add(channelGroup.toMap());
}
}
String? defaultIconPath;
if (kIsWeb) {
// For web release
} else {
if (!LocalAssertUtils.isNullOrEmptyOrInvalid(defaultIcon, String)) {
// To set a icon on top of notification, is mandatory to user a native resource
assert(LocalBitmapUtils().getMediaSource(defaultIcon!) ==
MediaSource.Resource);
defaultIconPath = defaultIcon;
}
}
final CallbackHandle? dartCallbackReference =
PluginUtilities.getCallbackHandle(dartIsolateMain);
var result = await methodChannel.invokeMethod(CHANNEL_METHOD_INITIALIZE, {
INITIALIZE_DEBUG_MODE: debug,
INITIALIZE_DEFAULT_ICON: defaultIconPath,
INITIALIZE_CHANNELS: serializedChannels,
INITIALIZE_CHANNELS_GROUPS: serializedChannelGroups,
BACKGROUND_HANDLE: dartCallbackReference!.toRawHandle()
});
LocalNotifications.localTimeZoneIdentifier = await methodChannel
.invokeMethod(CHANNEL_METHOD_GET_LOCAL_TIMEZONE_IDENTIFIER);
LocalNotifications.utcTimeZoneIdentifier = await methodChannel
.invokeMethod(CHANNEL_METHOD_GET_UTC_TIMEZONE_IDENTIFIER);
return result;
}