Add platform_services sample (#8058)
* Add platform_services sample
* update build.gradle to use latest scripts
* use FlutterActivity
* Updated ExampleInstrumentedTest.java and deleted FlutterPlugin.groovy
* Remove getRandom code from main.dart
* remove unused import
diff --git a/examples/platform_services/lib/main.dart b/examples/platform_services/lib/main.dart
new file mode 100644
index 0000000..a0870d3
--- /dev/null
+++ b/examples/platform_services/lib/main.dart
@@ -0,0 +1,55 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+
+class PlatformServices extends StatefulWidget {
+ @override
+ _PlatformServicesState createState() => new _PlatformServicesState();
+}
+
+class _PlatformServicesState extends State<PlatformServices> {
+ double _latitude;
+ double _longitude;
+
+ @override
+ Widget build(BuildContext context) {
+ return new Material(
+ child: new Center(
+ child: new Column(
+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+ children: <Widget>[
+ new Text('Hello from Flutter!'),
+ new RaisedButton(
+ child: new Text('Get Location'),
+ onPressed: _getLocation
+ ),
+ new Text('Latitude: $_latitude, Longitude: $_longitude'),
+ ]
+ )
+ )
+ );
+ }
+
+ Future<Null> _getLocation() async {
+ final Map<String, String> message = <String, String>{'provider': 'network'};
+ final Map<String, dynamic> reply = await PlatformMessages.sendJSON('getLocation', message);
+ // If the widget was removed from the tree while the message was in flight,
+ // we want to discard the reply rather than calling setState to update our
+ // non-existent appearance.
+ if (!mounted)
+ return;
+ setState(() {
+ _latitude = reply['latitude'].toDouble();
+ _longitude = reply['longitude'].toDouble();
+ });
+ }
+}
+
+void main() {
+ runApp(new PlatformServices());
+}