1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-10 14:58:34 +00:00

[federated_plugin_sample] modify the sample to expose battery API instead of geolocation API (#526)

This commit is contained in:
Ayush Bherwani
2020-08-25 11:52:42 +05:30
committed by GitHub
parent 033ae11733
commit 60691d00c0
17 changed files with 116 additions and 211 deletions

View File

@@ -2,8 +2,7 @@
// 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/location_method_channel.dart';
import 'package:federated_plugin_platform_interface/location_model.dart';
import 'package:federated_plugin_platform_interface/battery_method_channel.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -11,18 +10,17 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('MethodChannel test', () {
final location = Location(latitude: 1.0, longitude: 2.0);
MethodChannel('location').setMockMethodCallHandler((call) async {
if (call.method == 'getLocation') {
return [location.longitude, location.latitude];
final batteryLevel = 89;
MethodChannel('battery').setMockMethodCallHandler((call) async {
if (call.method == 'getBatteryLevel') {
return batteryLevel;
}
});
test('getLocation method test', () async {
final locationMethodChannel = LocationMethodChannel();
final result = await locationMethodChannel.getLocation();
expect(result.longitude, location.longitude);
expect(result.latitude, result.latitude);
test('getBatteryLevel method test', () async {
final locationMethodChannel = BatteryMethodChannel();
final result = await locationMethodChannel.getBatteryLevel();
expect(result, batteryLevel);
});
});
}