Files
2026-09-21 18:03:21 -04:00

87 lines
3.0 KiB
Dart

import 'package:flutter/material.dart';
/// Neutral palette. The accent colour comes from [AppSettings] through the
/// theme, so widgets read `Theme.of(context).colorScheme.primary` for it.
abstract final class OsColors {
static const background = Color(0xFF0A0C10);
static const surface = Color(0xFF13161C);
static const surfaceHigh = Color(0xFF1C2028);
static const good = Color(0xFF34C77B);
static const warn = Color(0xFFFFB020);
static const bad = Color(0xFFFF4D5E);
static const text = Color(0xFFF2F4F8);
static const textDim = Color(0xFF8A93A5);
static const track = Color(0xFF20252E);
static Color batteryColor(int? level) {
if (level == null) return track;
if (level <= 15) return bad;
if (level <= 30) return warn;
return good;
}
}
ThemeData buildOsTheme(Color accent) {
final onAccent = accent.computeLuminance() > 0.5 ? OsColors.background : Colors.white;
final base = ThemeData(
brightness: Brightness.dark,
useMaterial3: true,
colorScheme: ColorScheme.dark(
primary: accent,
onPrimary: onAccent,
secondary: accent,
onSecondary: onAccent,
surface: OsColors.background,
onSurface: OsColors.text,
surfaceContainerHighest: OsColors.surfaceHigh,
error: OsColors.bad,
),
scaffoldBackgroundColor: OsColors.background,
);
return base.copyWith(
appBarTheme: const AppBarTheme(
backgroundColor: OsColors.background,
foregroundColor: OsColors.text,
elevation: 0,
centerTitle: false,
),
cardTheme: const CardThemeData(
color: OsColors.surface,
elevation: 0,
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))),
),
filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom(
minimumSize: const Size(0, 52),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
textStyle: const TextStyle(fontWeight: FontWeight.w700, fontSize: 16),
),
),
segmentedButtonTheme: SegmentedButtonThemeData(
style: SegmentedButton.styleFrom(
selectedBackgroundColor: accent,
selectedForegroundColor: onAccent,
side: const BorderSide(color: OsColors.surfaceHigh),
),
),
switchTheme: SwitchThemeData(
thumbColor: WidgetStateProperty.resolveWith(
(s) => s.contains(WidgetState.selected) ? onAccent : OsColors.textDim),
trackColor: WidgetStateProperty.resolveWith(
(s) => s.contains(WidgetState.selected) ? accent : OsColors.surfaceHigh),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: OsColors.surfaceHigh,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide.none,
),
),
snackBarTheme: const SnackBarThemeData(behavior: SnackBarBehavior.floating),
progressIndicatorTheme: ProgressIndicatorThemeData(color: accent),
textTheme: base.textTheme.apply(bodyColor: OsColors.text, displayColor: OsColors.text),
);
}