gps_connectivity 0.0.4 copy "gps_connectivity: ^0.0.4" to clipboard
gps_connectivity: ^0.0.4 copied to clipboard

PlatformAndroid

A Flutter plugin that checks whether GPS is ON or OFF, it can listen for GPS change.

example/lib/main.dart

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

import 'package:gps_connectivity/gps_connectivity.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  late StreamSubscription subscription;
  bool isGpsEnabled = false;

  @override
  void initState() {
    super.initState();
    subscription =
        GpsConnectivity().onGpsConnectivityChanged.listen((bool isGpsEnabled) {
      setState(() {
        this.isGpsEnabled = isGpsEnabled;
      });
    });

    WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
      GpsConnectivity().checkGpsConnectivity().then((bool isGpsEnabled) {
        setState(() {
          this.isGpsEnabled = isGpsEnabled;
        });
      });
    });
  }

  @override
  void dispose() {
    subscription.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    String isOn = isGpsEnabled ? 'ON' : 'OFF';

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Gps Connectivity Plugin'),
        ),
        body: Center(
          child: Text(
            "Gps is $isOn",
            style: const TextStyle(fontSize: 24.0),
          ),
        ),
      ),
    );
  }
}
7
likes
140
pub points
78%
popularity

Publisher

unverified uploader

A Flutter plugin that checks whether GPS is ON or OFF, it can listen for GPS change.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, meta, plugin_platform_interface

More

Packages that depend on gps_connectivity