speed_settings_card.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import '../../core/theme/app_colors.dart';
  4. import '../../core/widgets/app_icon.dart';
  5. import '../home/obd_controller.dart';
  6. import '../home/telemetry_settings_controller.dart';
  7. import 'settings_widgets.dart';
  8. /// Settings card for showing speed on Home and choosing its source.
  9. class SpeedSettingsCard extends StatelessWidget {
  10. const SpeedSettingsCard({super.key});
  11. @override
  12. Widget build(BuildContext context) {
  13. final colors = context.colors;
  14. final theme = Theme.of(context);
  15. final telemetry = context.watch<TelemetrySettingsController>();
  16. final obd = context.watch<ObdController>();
  17. return Column(
  18. crossAxisAlignment: CrossAxisAlignment.start,
  19. children: [
  20. Row(
  21. children: [
  22. Container(
  23. width: 42,
  24. height: 42,
  25. decoration: BoxDecoration(
  26. color: colors.accentSoft,
  27. borderRadius: BorderRadius.circular(14),
  28. ),
  29. alignment: Alignment.center,
  30. child: AppIcon(
  31. 'assets/icons/gauge.svg',
  32. size: 20,
  33. color: colors.accent,
  34. ),
  35. ),
  36. const SizedBox(width: 14),
  37. Expanded(
  38. child: Column(
  39. crossAxisAlignment: CrossAxisAlignment.start,
  40. children: [
  41. Text('Show speed', style: theme.textTheme.titleMedium),
  42. const SizedBox(height: 2),
  43. Text(
  44. 'Show the speed card on the home screen.',
  45. style: theme.textTheme.bodySmall?.copyWith(
  46. color: colors.inkMuted,
  47. ),
  48. ),
  49. ],
  50. ),
  51. ),
  52. const SizedBox(width: 8),
  53. SettingsSwitch(
  54. value: telemetry.speedEnabled,
  55. semanticsLabel: telemetry.speedEnabled
  56. ? 'Hide the speed card'
  57. : 'Show the speed card',
  58. onChanged: telemetry.setSpeedEnabled,
  59. ),
  60. ],
  61. ),
  62. if (obd.hasConfiguredAdapter) ...[
  63. Divider(color: colors.border, height: 30),
  64. Row(
  65. children: [
  66. Expanded(
  67. child: Column(
  68. crossAxisAlignment: CrossAxisAlignment.start,
  69. children: [
  70. Text(
  71. 'Use OBD-II for speed',
  72. style: theme.textTheme.bodyLarge,
  73. ),
  74. const SizedBox(height: 2),
  75. Text(
  76. 'GPS is used when this is off.',
  77. style: theme.textTheme.bodySmall?.copyWith(
  78. color: colors.inkMuted,
  79. ),
  80. ),
  81. ],
  82. ),
  83. ),
  84. const SizedBox(width: 8),
  85. SettingsSwitch(
  86. value: telemetry.speedUseObd,
  87. semanticsLabel: telemetry.speedUseObd
  88. ? 'Use GPS for speed'
  89. : 'Use OBD-II for speed',
  90. onChanged: telemetry.setSpeedUseObd,
  91. ),
  92. ],
  93. ),
  94. ],
  95. ],
  96. );
  97. }
  98. }