1
0
mirror of https://github.com/flutter/samples.git synced 2026-03-30 00:02:02 +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,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:federated_plugin/federated_plugin.dart';
import 'package:federated_plugin_example/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -10,27 +9,23 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
group('federated plugin demo tests', () {
final location = Location(latitude: 131.0, longitude: 221.0);
final batteryLevel = 45;
setUpAll(() {
MethodChannel('location').setMockMethodCallHandler((call) async {
if (call.method == 'getLocation') {
return [location.longitude, location.latitude];
MethodChannel('battery').setMockMethodCallHandler((call) async {
if (call.method == 'getBatteryLevel') {
return batteryLevel;
}
});
});
testWidgets('get location from platform', (tester) async {
testWidgets('get current battery level from platform', (tester) async {
await tester.pumpWidget(MyApp());
// Tap button to get location from platform.
// Tap button to retrieve current battery level from platform.
await tester.tap(find.byType(RaisedButton));
await tester.pumpAndSettle();
expect(
find.text('Latitude: ${location.latitude}\n'
'Longitude: ${location.longitude}'),
findsOneWidget,
);
expect(find.text('Battery Level: $batteryLevel'), findsOneWidget);
});
});
}