mirror of https://github.com/flutter/samples.git
[federated_plugin_sample] modify the sample to expose battery API instead of geolocation API (#526)
parent
033ae11733
commit
60691d00c0
@ -1,5 +1,3 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="dev.flutter.federated_plugin">
|
package="dev.flutter.federated_plugin">
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2020 The Flutter team. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:federated_plugin_platform_interface/federated_plugin_platform_interface.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
/// Implements [FederatedPluginInterface] using [MethodChannel] to fetch
|
||||||
|
/// battery level from platform.
|
||||||
|
class BatteryMethodChannel extends FederatedPluginInterface {
|
||||||
|
static const MethodChannel _methodChannel = MethodChannel('battery');
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<int> getBatteryLevel() async {
|
||||||
|
return await _methodChannel.invokeMethod<int>('getBatteryLevel');
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
// Copyright 2020 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'package:federated_plugin_platform_interface/federated_plugin_platform_interface.dart';
|
|
||||||
import 'package:federated_plugin_platform_interface/location_model.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
|
|
||||||
/// Implements [FederatedPluginInterface] using [MethodChannel] to fetch
|
|
||||||
/// location from platform.
|
|
||||||
class LocationMethodChannel extends FederatedPluginInterface {
|
|
||||||
static const MethodChannel _methodChannel = MethodChannel('location');
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<Location> getLocation() async {
|
|
||||||
final result =
|
|
||||||
await _methodChannel.invokeMethod<List<dynamic>>('getLocation');
|
|
||||||
|
|
||||||
return Location(
|
|
||||||
longitude: result.first as double,
|
|
||||||
latitude: result.last as double,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
// Copyright 2020 The Flutter team. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
/// Model to hold the incoming latitude and longitude values from platform.
|
|
||||||
class Location {
|
|
||||||
final double latitude;
|
|
||||||
final double longitude;
|
|
||||||
|
|
||||||
Location({this.latitude, this.longitude});
|
|
||||||
}
|
|
Loading…
Reference in new issue