system_status.dart 971 B

123456789101112131415161718192021222324252627282930313233343536373839
  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});
  22. final int index;
  23. final int max;
  24. factory VolumeInfo.fromMap(Map<dynamic, dynamic> map) {
  25. return VolumeInfo(
  26. index: (map['index'] as num?)?.toInt() ?? 0,
  27. max: (map['max'] as num?)?.toInt() ?? 15,
  28. );
  29. }
  30. double get fraction => max <= 0 ? 0 : (index / max).clamp(0.0, 1.0);
  31. int get percent => (fraction * 100).round();
  32. }