关闭应用后,我需要通过“隔离”从后台进程发送通知 但我有错误 在不使用预定通知的情况下该怎么办,因为我需要执行特定的代码 注意: 如果此代码无法运行,请以其他方式建议我
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 / ViewRootImpl @ dbbebd7MainActivity:ViewPostIme指针0 D / ViewRootImpl @ dbbebd7MainActivity:ViewPostIme指针1 I / flutter( 1863):隔离I / flutter(1863):showNotification E / flutter(1863): [错误:flutter / runtime / dart_isolate.cc(805)]未处理的异常: E / flutter(1863):错误:本机函数'Window_sendPlatformMessage' 无法找到(4个参数)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 (包装: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)