Airplane mode service flutter

Viewed 1368
  • Basically i want to set airplane mode service on/off on button click in flutter. Unable to find any solution on internet. unable to find any dart library
1 Answers

Are you developing for Android or IOS or both? In Android, you will need to do the bulk of the work natively using a MethodChannel to communicate between Flutter and Android. Then you will need to call the native Notification.Service from Flutter, using your desired UI.

So on the android side your code will look something like this:

 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;
}

Then on the Flutter side:

class AppModel extends Model {
  final _platformChannel1 =
      MethodChannel('company.com/package/name');

  Future<Null> dndOn() async {
    await _platformChannel1.invokeMethod('AIRPLANE MODE ON');
    notifyListeners();
  }

Not sure about IOS...

Good luck, it's easier than it looks!

Related