large Flutter Favorite logosmall Flutter Favorite logo

geolocator 3.0.0 icon indicating copy to clipboard operation
geolocator: ^3.0.0 copied to clipboard

[pending analysis]

Geolocation plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API for generic location (GPS etc.) functions.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'pages/calculate_distance_widget.dart';
import 'pages/current_location_widget.dart';
import 'pages/location_stream_widget.dart';

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

enum TabItem { singleLocation, locationStream, distance }

class GeolocatorExampleApp extends StatefulWidget {
  @override
  State<GeolocatorExampleApp> createState() => BottomNavigationState();
}

class BottomNavigationState extends State<GeolocatorExampleApp> {
  TabItem _currentItem = TabItem.singleLocation;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Geolocator Example App'),
        ),
        body: _buildBody(),
        bottomNavigationBar: _buildBottomNavigationBar(),
      ),
    );
  }

  Widget _buildBody() {
    switch (_currentItem) {
      case TabItem.locationStream:
        return LocationStreamWidget();
      case TabItem.distance:
        return CalculateDistanceWidget();
      case TabItem.singleLocation:
      default:
        return CurrentLocationWidget();
    }
  }

  Widget _buildBottomNavigationBar() {
    return BottomNavigationBar(
      type: BottomNavigationBarType.fixed,
      items: <BottomNavigationBarItem>[
        _buildBottomNavigationBarItem(
            Icons.location_on, TabItem.singleLocation),
        _buildBottomNavigationBarItem(Icons.clear_all, TabItem.locationStream),
        _buildBottomNavigationBarItem(Icons.redo, TabItem.distance),
      ],
      onTap: _onSelectTab,
    );
  }

  BottomNavigationBarItem _buildBottomNavigationBarItem(
      IconData icon, TabItem tabItem) {
    final String text = tabItem.toString().split('.').last;
    final Color color =
        _currentItem == tabItem ? Theme.of(context).primaryColor : Colors.grey;

    return BottomNavigationBarItem(
      icon: Icon(
        icon,
        color: color,
      ),
      title: Text(
        text,
        style: TextStyle(
          color: color,
        ),
      ),
    );
  }

  void _onSelectTab(int index) {
    TabItem selectedTabItem;

    switch (index) {
      case 1:
        selectedTabItem = TabItem.locationStream;
        break;
      case 2:
        selectedTabItem = TabItem.distance;
        break;
      default:
        selectedTabItem = TabItem.singleLocation;
    }

    setState(() {
      _currentItem = selectedTabItem;
    });
  }
}
3930
likes
--
pub points
100%
popularity

Publisher

verified publisher iconbaseflow.com

Geolocation plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API for generic location (GPS etc.) functions.

Repository (GitHub)
View/report issues

License

Icon for licenses.unknown (LICENSE)

Dependencies

flutter, google_api_availability, meta, permission_handler

More

Packages that depend on geolocator