Flutter isolates using the flutter isolate package do not show notificaitons when the app has been killed.
Tried using the isolate package with dart:isolate, that does not work.
import 'dart:async';
import 'dart:isolate';
import 'package:flutter/material.dart';
import 'package:flutter_isolate/flutter_isolate.dart';
'package:flutter_local_notifications/flutter_local_notifications.dart';
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
Future onSelectNotification(String payload) async {
if (payload != null) {
debugPrint('notification payload: ' + payload);
}
}
void isolated(String args) async {
Timer.periodic(new Duration(seconds: 10), (Timer t) => print('hi!'));
Timer.periodic(new Duration(seconds: 10), (Timer y) async
{
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your channel id', 'your channel name', 'your channel description',
importance: Importance.Max,
priority: Priority.High,
ticker: 'ticker');
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0, 'plain title', 'plain body', platformChannelSpecifics,
payload: 'item x');
});
}
void main() async {
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
// If you have skipped STEP 3 then change app_icon to @mipmap/ic_launcher
var initializationSettingsAndroid =
new AndroidInitializationSettings('appicon');
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
isolated("hi");
}
The code above is what the system sees when the app has been killed as the state classes have terminated, and no longer exist. If we can get the code above running then the isolate will still work when the app has been killed by the user in Android and iOS and the state classes are no longer there.
Thanks in advance.
Rob.