flutter_gaode_map 0.0.1 copy "flutter_gaode_map: ^0.0.1" to clipboard
flutter_gaode_map: ^0.0.1 copied to clipboard

outdated

A new flutter plugin project.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:flutter_gaode_map/flutter_gaode_map.dart';
import 'package:flutter_gaode_map/text_view.dart';

void main() async{
  await FlutterGaodeMap.init('f5774b3003cfe257757b5415ef94f92b');
  runApp(MyApp());
}


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

class _MyAppState extends State<MyApp> {
  String _location = 'Unknown';
  MethodChannel _channel;
  FlutterGaodeMap _amapLocation = FlutterGaodeMap();
  StreamSubscription<String> _locationSubscription;

  @override
  void initState() {
    super.initState();
    _locationSubscription =
        _amapLocation.onLocationChanged.listen((String location) {
          print(location);
          if (!mounted) return;
          setState(() {
            _location = location;
          });
        });
//    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future

  <

  void

  >

  getLocation

  () async {
  String location;
  // Platform messages may fail, so we use a try/catch PlatformException.
  try {
  location = await _amapLocation.getLocation;
  print(location);
  } on PlatformException {
  location = '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;

  setState(() {
  _location = location;
  });
  }

  Future<void> startLocation() async {
  await _amapLocation.startLocation;
  }

  Future<void> stopLocation() async {
  await _amapLocation.stopLocation;
  }
  void _onTextViewCreated(TextViewController controller) {
  controller.setText('Hello from Android!');
  }
  @override
  Widget build(BuildContext context) {
  return new MaterialApp(
  home: new Scaffold(
  appBar: new AppBar(
  title: const Text('Plugin example app'),
  ),
  body: new Center(
  child: Column(
  children: <Widget>[
  Center(
  child: Container(
  padding: EdgeInsets.symmetric(vertical: 30.0),
  width: 130.0,
  height: 100.0,
  child: TextView(
  onTextViewCreated: _onTextViewCreated,
  ))),
  Container(child: AndroidView(
  viewType: 'plugins.nightfarmer.top/myview', creationParams: {
  "lat":"40.020082", "lng":"116.473302", "title":"测试地址"
  },
  creationParamsCodec: const StandardMessageCodec(),
  ), height: 200.0, ),
  new FlatButton(onPressed: startLocation, child: Text("开始定位")),
  new FlatButton(onPressed: stopLocation, child: Text("停止定位")),
  new Text('Running on: $_location\n'),
  ],
  ),
  ),
  ),
  );
  }

  @override
  void dispose()

  {
  super.dispose();
  if (_locationSubscription != null) {
  _locationSubscription.cancel();
  }
  }
}
0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

A new flutter plugin project.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_gaode_map