I need to send notifications from background process by Isolated when app is closed but I have the error How can I do that without use scheduled notification because I need to execute a specific code Note: If this code will not run please advice me in another way
import [...]
void main() {..}
class MyApp extends StatefulWidget {...}
class _MyAppState extends State<MyApp> {
static FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
void callerCreateIsolate() async {
await Isolate.spawn(
echo,
'',
);
}
static void echo(String s) {
print('isolate');
showNotification();
}
static Future onSelectNotification(String payload) {
debugPrint("payload : $payload");
showDialog(
builder: (_) =>
new AlertDialog(
title: new Text('Notification'),
content: new Text('$payload'),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text('Flutter Local Notification'),
),
body: new Center(
child: Column(
children: <Widget>[
new RaisedButton(
onPressed: callerCreateIsolate,
child: new Text(
'Isolate',
style: Theme
.of(context)
.textTheme
.headline,
),
),
],
)),
);
}
static showNotification() async {
print('showNotification');
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
var _android = new AndroidInitializationSettings('bigbenicon');
var _iOS = new IOSInitializationSettings();
var initSetttings = new InitializationSettings(_android, _iOS);
flutterLocalNotificationsPlugin.initialize(initSetttings,
onSelectNotification: onSelectNotification);
var android = new AndroidNotificationDetails(
'channel id', 'channel NAME', 'CHANNEL DESCRIPTION',
priority: Priority.High, importance: Importance.Max,
);
var iOS = new IOSNotificationDetails();
var platform = new NotificationDetails(android, iOS);
await flutterLocalNotificationsPlugin.show(0, 'title', 'body', platform,
payload: 'closed');
}
}
D/[email protected]: ViewPostIme pointer 0 D/[email protected]: ViewPostIme pointer 1 I/flutter ( 1863): isolate I/flutter ( 1863): showNotification E/flutter ( 1863): [ERROR:flutter/runtime/dart_isolate.cc(805)] Unhandled exception: E/flutter ( 1863): error: native function 'Window_sendPlatformMessage' (4 arguments) cannot be found E/flutter ( 1863): #0 Window.sendPlatformMessage (dart:ui/window.dart:1088:9) E/flutter ( 1863): #1 _DefaultBinaryMessenger._sendPlatformMessage (package:flutter/src/services/binary_messenger.dart:85:15) E/flutter ( 1863): #2 _DefaultBinaryMessenger.send (package:flutter/src/services/binary_messenger.dart:129:12) E/flutter ( 1863): #3 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:309:51) E/flutter ( 1863): E/flutter ( 1863): #4 FlutterLocalNotificationsPlugin.initialize (package:flutter_local_notifications/src/flutter_local_notifications.dart:103:24) E/flutter ( 1863): E/flutter ( 1863): #5 _MyAppState.showNotification (package:big_ben/main.dart:74:37) E/flutter ( 1863): E/flutter ( 1863): #6 _MyAppState.echo (package:big_ben/main.dart:29:4) E/flutter ( 1863): #7 _startIsolate. (dart:isolate-patch/isolate_patch.dart:304:17) E/flutter ( 1863): #8 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)