Enforce theme colors on switches

This commit is contained in:
Janez T
2026-03-15 10:56:47 +01:00
parent a124e3d9f2
commit 3e559a4f4e
3 changed files with 211 additions and 195 deletions

View File

@@ -774,7 +774,7 @@ class SensorMetricSelectorItem extends StatelessWidget {
),
),
),
Switch.adaptive(value: visible, onChanged: onToggle),
Switch(value: visible, onChanged: onToggle),
],
),
const SizedBox(height: 12),

View File

@@ -1875,7 +1875,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: Theme.of(context).textTheme.bodySmall,
),
),
Switch.adaptive(
Switch(
value: _showCurrentImagePreview,
onChanged: (value) {
setState(() => _showCurrentImagePreview = value);

View File

@@ -1,27 +1,50 @@
import 'package:flutter/material.dart';
enum AppThemeMode {
light,
dark,
sarRed,
sarGreen,
sarNavyBlue,
system,
}
enum AppThemeMode { light, dark, sarRed, sarGreen, sarNavyBlue, system }
class AppTheme {
static ThemeData _withSharedControls(ThemeData theme) {
final colorScheme = theme.colorScheme;
return theme.copyWith(
switchTheme: SwitchThemeData(
thumbColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.disabled)) {
return colorScheme.onSurface.withValues(alpha: 0.38);
}
if (states.contains(WidgetState.selected)) {
return colorScheme.onPrimary;
}
return colorScheme.outline;
}),
trackColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.disabled)) {
return colorScheme.onSurface.withValues(alpha: 0.12);
}
if (states.contains(WidgetState.selected)) {
return colorScheme.primary;
}
return colorScheme.surfaceContainerHighest;
}),
trackOutlineColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) {
return colorScheme.primary;
}
return colorScheme.outlineVariant;
}),
),
);
}
// Light theme (Blue)
static ThemeData get lightTheme {
return ThemeData(
return _withSharedControls(
ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.blue,
brightness: Brightness.light,
),
appBarTheme: const AppBarTheme(
centerTitle: true,
elevation: 0,
),
appBarTheme: const AppBarTheme(centerTitle: true, elevation: 0),
cardTheme: CardThemeData(
elevation: 2,
shape: RoundedRectangleBorder(
@@ -29,26 +52,23 @@ class AppTheme {
),
),
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
filled: true,
),
),
);
}
// Dark theme (Blue)
static ThemeData get darkTheme {
return ThemeData(
return _withSharedControls(
ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.blue,
brightness: Brightness.dark,
),
appBarTheme: const AppBarTheme(
centerTitle: true,
elevation: 0,
),
appBarTheme: const AppBarTheme(centerTitle: true, elevation: 0),
cardTheme: CardThemeData(
elevation: 2,
shape: RoundedRectangleBorder(
@@ -56,17 +76,17 @@ class AppTheme {
),
),
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
filled: true,
),
),
);
}
// SAR Red theme (Emergency/Alert tones)
static ThemeData get sarRedTheme {
return ThemeData(
return _withSharedControls(
ThemeData(
useMaterial3: true,
colorScheme: const ColorScheme.dark(
brightness: Brightness.dark,
@@ -100,10 +120,7 @@ class AppTheme {
color: const Color(0xFF2D0000),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: const BorderSide(
color: Color(0xFFFF5252),
width: 1,
),
side: const BorderSide(color: Color(0xFFFF5252), width: 1),
),
),
inputDecorationTheme: InputDecorationTheme(
@@ -120,12 +137,14 @@ class AppTheme {
foregroundColor: const Color(0xFF000000),
),
),
),
);
}
// SAR Green theme (All Clear/Safe tones)
static ThemeData get sarGreenTheme {
return ThemeData(
return _withSharedControls(
ThemeData(
useMaterial3: true,
colorScheme: const ColorScheme.dark(
brightness: Brightness.dark,
@@ -159,10 +178,7 @@ class AppTheme {
color: const Color(0xFF002D1F),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: const BorderSide(
color: Color(0xFF69F0AE),
width: 1,
),
side: const BorderSide(color: Color(0xFF69F0AE), width: 1),
),
),
inputDecorationTheme: InputDecorationTheme(
@@ -179,12 +195,14 @@ class AppTheme {
foregroundColor: const Color(0xFF000000),
),
),
),
);
}
// SAR Navy Blue theme (Professional/Operations tones)
static ThemeData get sarNavyBlueTheme {
return ThemeData(
return _withSharedControls(
ThemeData(
useMaterial3: true,
colorScheme: const ColorScheme.dark(
brightness: Brightness.dark,
@@ -218,10 +236,7 @@ class AppTheme {
color: const Color(0xFF001A2D),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: const BorderSide(
color: Color(0xFF5C9FFF),
width: 1,
),
side: const BorderSide(color: Color(0xFF5C9FFF), width: 1),
),
),
inputDecorationTheme: InputDecorationTheme(
@@ -238,6 +253,7 @@ class AppTheme {
foregroundColor: const Color(0xFF000000),
),
),
),
);
}