| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- import '../../core/theme/app_colors.dart';
- import '../../core/widgets/app_icon.dart';
- import '../home/obd_controller.dart';
- import '../home/telemetry_settings_controller.dart';
- import 'settings_widgets.dart';
- /// Settings card for the outside-temperature row and its data source.
- class TemperatureSettingsCard extends StatelessWidget {
- const TemperatureSettingsCard({super.key});
- @override
- Widget build(BuildContext context) {
- final colors = context.colors;
- final theme = Theme.of(context);
- final telemetry = context.watch<TelemetrySettingsController>();
- final obd = context.watch<ObdController>();
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- Container(
- width: 42,
- height: 42,
- decoration: BoxDecoration(
- color: colors.accentSoft,
- borderRadius: BorderRadius.circular(14),
- ),
- alignment: Alignment.center,
- child: AppIcon(
- 'assets/icons/thermometer.svg',
- size: 20,
- color: colors.accent,
- ),
- ),
- const SizedBox(width: 14),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text('Show temperature', style: theme.textTheme.titleMedium),
- const SizedBox(height: 2),
- Text(
- 'Show the outside temperature below the clock.',
- style: theme.textTheme.bodySmall?.copyWith(
- color: colors.inkMuted,
- ),
- ),
- ],
- ),
- ),
- const SizedBox(width: 8),
- SettingsSwitch(
- value: telemetry.temperatureEnabled,
- semanticsLabel: telemetry.temperatureEnabled
- ? 'Hide the outside temperature'
- : 'Show the outside temperature',
- onChanged: (value) async {
- final ok = await telemetry.setTemperatureEnabled(value);
- if (!ok && context.mounted) {
- _message(
- context,
- telemetry.weatherError ??
- 'Location permission is required for weather.',
- );
- }
- },
- ),
- ],
- ),
- if (obd.hasConfiguredAdapter && telemetry.temperatureEnabled) ...[
- Divider(color: colors.border, height: 30),
- Row(
- children: [
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- 'Use OBD-II for temperature',
- style: theme.textTheme.bodyLarge,
- ),
- const SizedBox(height: 2),
- Text(
- 'GPS and the weather provider are used when this is off.',
- style: theme.textTheme.bodySmall?.copyWith(
- color: colors.inkMuted,
- ),
- ),
- ],
- ),
- ),
- const SizedBox(width: 8),
- SettingsSwitch(
- value: telemetry.temperatureUseObd,
- semanticsLabel: telemetry.temperatureUseObd
- ? 'Use GPS and weather for temperature'
- : 'Use OBD-II for temperature',
- onChanged: (value) async {
- final ok = await telemetry.setTemperatureUseObd(value);
- if (!ok && context.mounted) {
- _message(
- context,
- telemetry.weatherError ??
- 'Location permission is required for weather.',
- );
- }
- },
- ),
- ],
- ),
- ],
- if (telemetry.temperatureEnabled &&
- telemetry.weatherError != null &&
- (!telemetry.weatherEnabled || !telemetry.temperatureUseObd)) ...[
- const SizedBox(height: 6),
- Text(
- telemetry.weatherError!,
- style: theme.textTheme.bodySmall?.copyWith(color: colors.inkMuted),
- ),
- ],
- ],
- );
- }
- void _message(BuildContext context, String message) {
- final messenger = ScaffoldMessenger.of(context);
- messenger.hideCurrentSnackBar();
- messenger.showSnackBar(SnackBar(content: Text(message)));
- }
- }
|