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);
                            }),
                      )
                    ]
                )
            )
        )
    );
  }
}
copied to clipboard
4
likes
40
points
20
downloads

Publisher

unverified uploader

Weekly Downloads

2024.10.07 - 2025.04.21

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

Repository (GitHub)

License

MIT (license)

Dependencies

flutter, fluttertoast

More

Packages that depend on airplane_mode_detection