airplane_mode_checker 3.0.0 copy "airplane_mode_checker: ^3.0.0" to clipboard
airplane_mode_checker: ^3.0.0 copied to clipboard

Flutter plugin allows you to check the status of Airplane Mode on iOS and Android mobile.

example/lib/main.dart

import 'dart:async';
import 'dart:developer';

import 'package:airplane_mode_checker/airplane_mode_checker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

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

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

  //Setup LongToast
  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 AirplaneModeChecker.instance.getPlatformVersion())!;
    } 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: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Version $_platformVersion'),
              ElevatedButton(
                child: const Text('Check AirplaneMode'),
                onPressed: () async {
                  final status =
                      await AirplaneModeChecker.instance.checkAirplaneMode();
                  if (status == AirplaneModeStatus.on) {
                    showLongToast('ON');
                    log('ON');
                  } else {
                    showLongToast('OFF');
                    log('OFF');
                  }
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
16
likes
160
points
4.01k
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin allows you to check the status of Airplane Mode on iOS and Android mobile.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on airplane_mode_checker