bmap_location_fluttify 0.1.0 copy "bmap_location_fluttify: ^0.1.0" to clipboard
bmap_location_fluttify: ^0.1.0 copied to clipboard

An `BaiduMap` Location Component, Powered By `Fluttify` Engine, Which Generates Dart Binding For Native SDK.

example/lib/main.dart

import 'package:bmap_location_fluttify/bmap_location_fluttify.dart';
import 'package:decorated_flutter/decorated_flutter.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await BmapLocation.instance.init(iosKey: 'CxZGl9DZx5p3PaST3y3azmmTXCAjNUcI');
  runApp(MyApp());
}

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

class _MyAppState extends State<MyApp> {
  Location _location;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: DecoratedColumn(
          padding: EdgeInsets.symmetric(horizontal: kSpaceLarge),
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              child: Text('获取单次定位'),
              onPressed: () async {
                if (await requestPermission()) {
                  final location = await BmapLocation.instance.fetchLocation();
                  setState(() => _location = location);
                }
              },
            ),
            RaisedButton(
              child: Text('获取连续定位'),
              onPressed: () async {
//                if (await requestPermission()) {
//                  await for (final location in BmapLocation.listenLocation()) {
//                    setState(() => _location = location);
//                  }
//                }
              },
            ),
            RaisedButton(
              child: Text('停止定位'),
              onPressed: () async {
                if (await requestPermission()) {
                  await BmapLocation.instance.stop();
                  setState(() => _location = null);
                }
              },
            ),
            if (_location != null)
              Center(
                child: Text(
                  _location.toString(),
                  textAlign: TextAlign.center,
                ),
              ),
          ],
        ),
      ),
    );
  }
}

Future<bool> requestPermission() async {
  final status = await Permission.location.request();

  if (status == PermissionStatus.granted) {
    return true;
  } else {
    toast('需要定位权限!');
    return false;
  }
}
0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

An `BaiduMap` Location Component, Powered By `Fluttify` Engine, Which Generates Dart Binding For Native SDK.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

bmap_core_fluttify, core_location_fluttify, flutter, foundation_fluttify

More

Packages that depend on bmap_location_fluttify