system_status.dart 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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({this.index = 0, this.max = 15, this.fixed = false});
  22. final int index;
  23. final int max;
  24. /// True when Android delegates volume to a fixed hardware amplifier (common
  25. /// on car head units). Apps cannot change that volume.
  26. final bool fixed;
  27. factory VolumeInfo.fromMap(Map<dynamic, dynamic> map) {
  28. return VolumeInfo(
  29. index: (map['index'] as num?)?.toInt() ?? 0,
  30. max: (map['max'] as num?)?.toInt() ?? 15,
  31. fixed: map['fixed'] == true,
  32. );
  33. }
  34. double get fraction => max <= 0 ? 0 : (index / max).clamp(0.0, 1.0);
  35. int get percent => (fraction * 100).round();
  36. }