| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /// Battery and connectivity snapshot shown on the home screen.
- class SystemStatus {
- const SystemStatus({
- this.batteryLevel = 0,
- this.charging = false,
- this.wifi = false,
- });
- final int batteryLevel;
- final bool charging;
- final bool wifi;
- factory SystemStatus.fromMap(Map<dynamic, dynamic> map) {
- return SystemStatus(
- batteryLevel: (map['batteryLevel'] as num?)?.toInt() ?? 0,
- charging: map['charging'] == true,
- wifi: map['wifi'] == true,
- );
- }
- }
- /// Current media-stream volume and its maximum.
- class VolumeInfo {
- const VolumeInfo({
- this.index = 0,
- this.max = 15,
- this.fixed = false,
- this.streams = const {},
- });
- final int index;
- final int max;
- /// True when Android delegates volume to a fixed hardware amplifier (common
- /// on car head units). Apps cannot change that volume.
- final bool fixed;
- /// Raw indices for every stream, used by the on-screen diagnostics panel.
- final Map<String, int> streams;
- factory VolumeInfo.fromMap(Map<dynamic, dynamic> map) {
- final rawStreams = map['streams'];
- final streams = <String, int>{};
- if (rawStreams is Map) {
- rawStreams.forEach((key, value) {
- if (key is String && value is num) {
- streams[key] = value.toInt();
- }
- });
- }
- return VolumeInfo(
- index: (map['index'] as num?)?.toInt() ?? 0,
- max: (map['max'] as num?)?.toInt() ?? 15,
- fixed: map['fixed'] == true,
- streams: streams,
- );
- }
- double get fraction => max <= 0 ? 0 : (index / max).clamp(0.0, 1.0);
- int get percent => (fraction * 100).round();
- }
|