airplane_mode_detection 1.0.0 copy "airplane_mode_detection: ^1.0.0" to clipboard
airplane_mode_detection: ^1.0.0 copied to clipboard

Flutter plugin that allows you to detect and check mobile airplane mode callback functions on iOS and Android.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:airplane_mode_detection/airplane_mode_detection.dart';
import 'package:fluttertoast/fluttertoast.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  void showLongToast(String state) {
    Fluttertoast.showToast(
      msg: state,
      toastLength: Toast.LENGTH_LONG,
    );
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await AirplaneModeDetection.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: new Scaffold(
            body: new Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [

                      Padding(
                        padding: const EdgeInsets.all(10.0),
                        child: new RaisedButton(
                            child: new Text('Check AirplaneMode'),
                            onPressed: () async {
                              String state = await AirplaneModeDetection.detectAirplaneMode();
                              showLongToast(state);
                              print(state);
                            }),
                      )
                    ]
                )
            )
        )
    );
  }
}
4
likes
40
pub points
54%
popularity

Publisher

unverified uploader

Flutter plugin that allows you to detect and check mobile airplane mode callback functions on iOS and Android.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter, fluttertoast

More

Packages that depend on airplane_mode_detection