ai_amap 1.1.0
ai_amap: ^1.1.0 copied to clipboard

Flutter Android iOS macOS

A new Flutter plugin about amap,support map location navi search.

example/lib/main.dart

import 'package:ai_amap/ai_amap.dart';
import 'package:ai_amap_example/app_location_address_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:permission_handler/permission_handler.dart';

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

///
/// 高德地图插件
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _requestPermissionIsGranted = false;

  AppAMapLocationAddressWidget _aMapWidget;
  @override
  void initState() {
    super.initState();
    _requestPermission();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(
          child: _requestPermissionIsGranted
              ? _aMapWidget ?? AppAMapLocationAddressWidget.defaultStyle()
              : Center(
                  child: MaterialButton(
                    color: Theme.of(context).primaryColor,
                    textColor: Colors.white,
                    onPressed: () {
                      _requestPermission();
                    },
                    child: Text("请求所需权限"),
                  ),
                ),
        ),
      ),
    );
  }

  ///
  /// Request permission
  /// request permission before all of aMap operate
  _requestPermission() async {
    var platform = Theme.of(context).platform;
    if (TargetPlatform.android == platform) {
      _requestAndroidPermission();
    } else if (TargetPlatform.iOS == platform) {
      _requestIosPermission();
    }
  }

  ///
  /// Request android needs permissions
  _requestAndroidPermission() async {
    if (await Permission.locationAlways.request().isGranted) {
      if (await Permission.storage.request().isGranted) {
        if (await Permission.phone.request().isGranted) {
          // Either the permission was already granted before or the user just granted it.
          setState(() {
            _requestPermissionIsGranted = true;
          });
        }
      }
    }
  }

  ///
  /// Request ios needs permission
  _requestIosPermission() async {
    if (await Permission.locationAlways.request().isGranted) {
      if (await Permission.storage.request().isGranted) {
        // Either the permission was already granted before or the user just granted it.
        setState(() {
          _requestPermissionIsGranted = true;
        });
      }
    }
  }
}
2
likes
100
pub points
40%
popularity

A new Flutter plugin about amap,support map location navi search.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

xkrossiafirstgm@gmail.com

License

BSD (LICENSE)

Dependencies

flutter

More

Packages that depend on ai_amap