Update platform_services to query battery level instead of location. (#8554)
diff --git a/examples/platform_services/lib/main.dart b/examples/platform_services/lib/main.dart
index 22a397a..f1a7ab0 100644
--- a/examples/platform_services/lib/main.dart
+++ b/examples/platform_services/lib/main.dart
@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
+import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -13,20 +14,23 @@
}
class _PlatformServicesState extends State<PlatformServices> {
- static const PlatformMethodChannel platform = const PlatformMethodChannel('geo');
- String _location = 'Unknown location.';
+ static const PlatformMethodChannel platform = const PlatformMethodChannel('battery');
+ String _batteryLevel = 'Unknown battery level.';
- Future<Null> _getLocation() async {
- String location;
- try {
- final List<double> result = await platform.invokeMethod('getLocation', 'network');
- location = 'Latitude ${result[0]}, Longitude ${result[1]}.';
- } on PlatformException catch (e) {
- location = "Failed to get location: '${e.message}'.";
+ Future<Null> _getBatteryLevel() async {
+ String batteryLevel;
+ if (Platform.isIOS) {
+ batteryLevel = "iOS is not supported yet.";
+ } else {
+ try {
+ final int result = await platform.invokeMethod('getBatteryLevel');
+ batteryLevel = 'Battery level at $result. %';
+ } on PlatformException catch (e) {
+ batteryLevel = "Failed to get battery level: '${e.message}'.";
+ }
}
-
setState(() {
- _location = location;
+ _batteryLevel = batteryLevel;
});
}
@@ -38,17 +42,17 @@
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new RaisedButton(
- child: new Text('Get Location'),
- onPressed: _getLocation,
+ child: new Text('Get Battery Level'),
+ onPressed: _getBatteryLevel,
),
- new Text(_location)
+ new Text(_batteryLevel)
],
- ),
- ),
+ )
+ )
);
}
}
-
+
void main() {
runApp(new PlatformServices());
}