obd_card.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'package:flutter/material.dart';
  2. import '../../../core/theme/app_colors.dart';
  3. import '../../../core/widgets/surface_card.dart';
  4. /// Compact live car data shown only while the ELM327 adapter is delivering
  5. /// fresh speed/throttle values.
  6. class ObdCard extends StatelessWidget {
  7. const ObdCard({
  8. super.key,
  9. required this.speedKmh,
  10. required this.throttlePercent,
  11. this.compact = false,
  12. });
  13. final double? speedKmh;
  14. final double? throttlePercent;
  15. final bool compact;
  16. @override
  17. Widget build(BuildContext context) {
  18. final colors = context.colors;
  19. final theme = Theme.of(context);
  20. final throttle = (throttlePercent ?? 0).clamp(0.0, 100.0);
  21. return SurfaceCard(
  22. padding: EdgeInsets.fromLTRB(
  23. compact ? 16 : 20,
  24. compact ? 13 : 16,
  25. compact ? 16 : 20,
  26. compact ? 13 : 16,
  27. ),
  28. radius: 24,
  29. child: Column(
  30. crossAxisAlignment: CrossAxisAlignment.start,
  31. children: [
  32. Row(
  33. children: [
  34. Container(
  35. width: 7,
  36. height: 7,
  37. decoration: BoxDecoration(
  38. color: colors.accent,
  39. shape: BoxShape.circle,
  40. ),
  41. ),
  42. const SizedBox(width: 8),
  43. Text(
  44. 'OBD-II',
  45. style: theme.textTheme.labelMedium?.copyWith(
  46. color: colors.inkMuted,
  47. letterSpacing: 0.8,
  48. ),
  49. ),
  50. const Spacer(),
  51. Text(
  52. 'LIVE',
  53. style: theme.textTheme.labelSmall?.copyWith(
  54. color: colors.accent,
  55. fontWeight: FontWeight.w700,
  56. letterSpacing: 0.8,
  57. ),
  58. ),
  59. ],
  60. ),
  61. SizedBox(height: compact ? 6 : 8),
  62. Row(
  63. crossAxisAlignment: CrossAxisAlignment.end,
  64. children: [
  65. Text(
  66. speedKmh == null ? '—' : speedKmh!.round().toString(),
  67. style: theme.textTheme.displaySmall?.copyWith(
  68. fontSize: compact ? 38 : 46,
  69. height: 0.95,
  70. fontFeatures: const [FontFeature.tabularFigures()],
  71. ),
  72. ),
  73. const SizedBox(width: 7),
  74. Padding(
  75. padding: const EdgeInsets.only(bottom: 5),
  76. child: Text(
  77. 'km/h',
  78. style: theme.textTheme.bodySmall?.copyWith(
  79. color: colors.inkMuted,
  80. ),
  81. ),
  82. ),
  83. ],
  84. ),
  85. SizedBox(height: compact ? 7 : 9),
  86. Row(
  87. children: [
  88. Text(
  89. 'Throttle',
  90. style: theme.textTheme.bodySmall?.copyWith(
  91. color: colors.inkMuted,
  92. ),
  93. ),
  94. const Spacer(),
  95. Text(
  96. '${throttle.round()}%',
  97. style: theme.textTheme.labelMedium?.copyWith(
  98. color: colors.ink,
  99. fontFeatures: const [FontFeature.tabularFigures()],
  100. ),
  101. ),
  102. ],
  103. ),
  104. const SizedBox(height: 5),
  105. ClipRRect(
  106. borderRadius: BorderRadius.circular(999),
  107. child: TweenAnimationBuilder<double>(
  108. tween: Tween(begin: 0, end: throttle / 100),
  109. duration: const Duration(milliseconds: 180),
  110. curve: Curves.easeOut,
  111. builder: (context, value, _) {
  112. return LinearProgressIndicator(
  113. value: value,
  114. minHeight: compact ? 5 : 6,
  115. backgroundColor: colors.border,
  116. valueColor: AlwaysStoppedAnimation(colors.accent),
  117. );
  118. },
  119. ),
  120. ),
  121. ],
  122. ),
  123. );
  124. }
  125. }