60 lines
1.3 KiB
Dart
60 lines
1.3 KiB
Dart
/// Small pure helpers for layout, formatting, and user-facing strings.
|
|
library;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'constants.dart';
|
|
|
|
/// Horizontal padding that grows a little on wider screens.
|
|
double pagePadding(double width) {
|
|
if (width >= Breakpoints.medium) return 32;
|
|
if (width >= Breakpoints.compact) return 24;
|
|
return 16;
|
|
}
|
|
|
|
/// Formats [date] as `MMM d, y` without pulling in `intl`.
|
|
String formatDate(DateTime date) {
|
|
const months = [
|
|
'Jan',
|
|
'Feb',
|
|
'Mar',
|
|
'Apr',
|
|
'May',
|
|
'Jun',
|
|
'Jul',
|
|
'Aug',
|
|
'Sep',
|
|
'Oct',
|
|
'Nov',
|
|
'Dec',
|
|
];
|
|
return '${months[date.month - 1]} ${date.day}, ${date.year}';
|
|
}
|
|
|
|
/// Converts a stored theme key into a [ThemeMode].
|
|
ThemeMode themeModeFromName(String name) {
|
|
return switch (name) {
|
|
'light' => ThemeMode.light,
|
|
'dark' => ThemeMode.dark,
|
|
_ => ThemeMode.system,
|
|
};
|
|
}
|
|
|
|
/// Inverse of [themeModeFromName] for persistence.
|
|
String nameFromThemeMode(ThemeMode mode) {
|
|
return switch (mode) {
|
|
ThemeMode.light => 'light',
|
|
ThemeMode.dark => 'dark',
|
|
ThemeMode.system => 'system',
|
|
};
|
|
}
|
|
|
|
/// Title-cases a [ThemeMode] for settings labels.
|
|
String labelForThemeMode(ThemeMode mode) {
|
|
return switch (mode) {
|
|
ThemeMode.light => 'Light',
|
|
ThemeMode.dark => 'Dark',
|
|
ThemeMode.system => 'System',
|
|
};
|
|
}
|