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:
@@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user