location_plugin 0.0.1

Flutter Android iOS

A location Flutter plugin.

example/lib/main.dart

import 'dart:developer';

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

import 'package:flutter/services.dart';
import 'package:location_plugin/location_plugin.dart';

void main() {
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> getMyLocation() async {
    String myLocation;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      Map<String, dynamic> map = await LocationPlugin.getLocation;
      print(map);
      myLocation = map["name"] as String;
      log(myLocation);
    } on PlatformException {
      myLocation = 'Failed to get location.';
    }

    // 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;

  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: RaisedButton(
            onPressed: getMyLocation,
            child: Text('get location'),
          )
        ),
      ),
    );
  }
}
1
likes
75
pub points
12%
popularity

A location Flutter plugin.

Homepage

Documentation

API reference

Uploader

sunkaiyu@gmail.com

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on location_plugin