system_status.dart 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /// Battery and connectivity snapshot shown on the home screen.
  2. class SystemStatus {
  3. const SystemStatus({
  4. this.batteryLevel = 0,
  5. this.charging = false,
  6. this.wifi = false,
  7. });
  8. final int batteryLevel;
  9. final bool charging;
  10. final bool wifi;
  11. factory SystemStatus.fromMap(Map<dynamic, dynamic> map) {
  12. return SystemStatus(
  13. batteryLevel: (map['batteryLevel'] as num?)?.toInt() ?? 0,
  14. charging: map['charging'] == true,
  15. wifi: map['wifi'] == true,
  16. );
  17. }
  18. }
  19. /// Current media-stream volume and its maximum.
  20. class VolumeInfo {
  21. const VolumeInfo({
  22. this.index = 0,
  23. this.max = 15,
  24. this.fixed = false,
  25. this.streams = const {},
  26. });
  27. final int index;
  28. final int max;
  29. /// True when Android delegates volume to a fixed hardware amplifier (common
  30. /// on car head units). Apps cannot change that volume.
  31. final bool fixed;
  32. /// Raw indices for every stream, used by the on-screen diagnostics panel.
  33. final Map<String, int> streams;
  34. factory VolumeInfo.fromMap(Map<dynamic, dynamic> map) {
  35. final rawStreams = map['streams'];
  36. final streams = <String, int>{};
  37. if (rawStreams is Map) {
  38. rawStreams.forEach((key, value) {
  39. if (key is String && value is num) {
  40. streams[key] = value.toInt();
  41. }
  42. });
  43. }
  44. return VolumeInfo(
  45. index: (map['index'] as num?)?.toInt() ?? 0,
  46. max: (map['max'] as num?)?.toInt() ?? 15,
  47. fixed: map['fixed'] == true,
  48. streams: streams,
  49. );
  50. }
  51. double get fraction => max <= 0 ? 0 : (index / max).clamp(0.0, 1.0);
  52. int get percent => (fraction * 100).round();
  53. }