Husnain Asghar
Husnain Asghar

Reputation: 59

Airplane mode service flutter

Upvotes: 5

Views: 2741

Answers (1)

Code Poet
Code Poet

Reputation: 8013

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!

Upvotes: 5

Related Questions