/
battery_plus_platform_interface.dart
60 lines (48 loc) · 2.18 KB
/
battery_plus_platform_interface.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'src/battery_plus_method_channel.dart';
import 'src/enums.dart';
export 'src/enums.dart';
/// The interface that implementations of Battery must implement.
///
/// Platform implementations should extend this class rather than implement it as `Battery`
/// does not consider newly added methods to be breaking changes. Extending this class
/// (using `extends`) ensures that the subclass will get the default implementation, while
/// platform implementations that `implements` this interface will be broken by newly added
/// [BatteryPlatform] methods.
abstract class BatteryPlatform extends PlatformInterface {
/// Constructs a BatteryPlatform.
BatteryPlatform() : super(token: _token);
static final Object _token = Object();
static BatteryPlatform _instance = MethodChannelBattery();
/// The default instance of [BatteryPlatform] to use.
///
/// Defaults to [MethodChannelBattery].
static BatteryPlatform get instance => _instance;
/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [BatteryPlatform] when they register themselves.
static set instance(BatteryPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}
/// Returns the current battery level in percent.
Future<int> get batteryLevel {
throw UnimplementedError('batteryLevel() has not been implemented.');
}
/// Returns true if the device is on battery save mode
Future<bool> get isInBatterySaveMode {
throw UnimplementedError('isInBatterySaveMode() has not been implemented.');
}
/// Returns the current battery state in percent.
Future<BatteryState> get batteryState {
throw UnimplementedError('batteryState() has not been implemented.');
}
/// Returns a Stream of BatteryState changes.
Stream<BatteryState> get onBatteryStateChanged {
throw UnimplementedError(
'get onBatteryStateChanged has not been implemented.');
}
}