您是在开发Android还是IOS或同时开发两者?在Android中,您将需要使用MethodChannel在本地进行大量工作,以便在Flutter和Android之间进行通信。然后,您将需要使用所需的UI从Flutter调用本机Notification.Service。
因此在android方面,您的代码将如下所示:
new MethodChannel(getFlutterView(), CHANNEL1).setMethodCallHandler(new MethodCallHandler() {
final NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
@Override
public void onMethodCall(@NonNull MethodCall methodCall, @NonNull Result result) {
switch (methodCall.method) {
case "AIRPLANE MODE ON":
assert mNotificationManager != null;
mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE);
break;
}
然后在Flutter一侧:
class AppModel extends Model {
final _platformChannel1 =
MethodChannel('company.com/package/name');
Future<Null> dndOn() async {
await _platformChannel1.invokeMethod('AIRPLANE MODE ON');
notifyListeners();
}
不确定IOS ...
祝你好运,比看起来容易!