Twenty-eight commits landed on the web app and the API since the phone was last touched, and the phone's own README opens by claiming full feature parity. It was not a small drift: a whole tab, two whole cards, and the two settings that decide how a time is read. The scheduler arrives as the third charging tab. One list of tasks covering every charger the account owns, where the charger's own cloud schedule is one window inside one box. A task is a flow — start at 23:00, cap to 10 A at 01:00, stop at 06:30 — on the days and the chargers it names, and naming no charger means all of them, including the ones imported later. The clock is the server's, so the tab only writes tasks and reads back how each one last went, and any step can be fired now to find out whether it will reach the charger before the night it matters. The RFID card comes with it: the list the account holds, a card added by its number or by holding it against the charger's own reader, and the charger's own list read back from the device. Both halves are written by every add and remove and they can still come apart, so when they disagree the card says which list each card is missing from — nothing else on the page would. The charger settings card the phone never had at all goes in whole rather than only its new half. Over Modbus that is the four writable registers; over the cloud it is the charger's whole settings group in sections, drawn from the same block table the web reads, one write per section because the charger takes a command whole and a schedule carrying only its switch is a schedule whose times have just been set to midnight. The clock and the week become settings. format.dart grows formatTime, the weekday order and the short names, with "auto" asking intl's own hour pattern and FIRSTDAYOFWEEK rather than a table here; Settings › Appearance asks both questions beneath the date. Flutter's own picker renders on the device locale, which nothing in this app steers, so TimeField types four digits on whichever clock is in force and keeps the meridiem as its own control — a box reading 13:45 beside a dial saying 01:45 PM is the disagreement the setting exists to end. The smaller ones travel too. The control card says which charger its buttons drive, picture and name, because it follows a serial and not the highlighted row; its two tiles take the names of the readings they actually hold; and the limit slider leaves it wherever a settings card now owns that value. The list's reachability re-asks every thirty seconds while the tab is in front, merged rather than replaced — "we could not ask" is not an answer, and it certainly is not "unknown". A settings frame that answers half a minute late is chased at widening gaps and then given up on. The information card names the fields the service sent under its own names and groups list records under their own, so list[0].* stops being read as one alphabetical run. An inherited integration field shows what it inherited rather than an example. The sign-in fields say nothing until you type. One gap stays open, and deliberately. The task form sends the phone's zone only when Dart reports an IANA name; Android usually answers with an abbreviation like CEST, which is not a zone, so it sends nothing and the server falls back to its own clock. A name the server would misread is worse than no name. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
111 lines
4.1 KiB
Dart
111 lines
4.1 KiB
Dart
import "package:flutter/material.dart";
|
|
import "package:shared_preferences/shared_preferences.dart";
|
|
|
|
import "models.dart";
|
|
|
|
/// App-wide appearance preferences (theme / locale / date format / currency /
|
|
/// font size), mirroring the web app's prefs.js. Persisted to SharedPreferences
|
|
/// so the chosen theme survives a restart before /api/me loads, and exposed as a
|
|
/// ChangeNotifier so MaterialApp and date formatting react to changes.
|
|
class AppSettings extends ChangeNotifier {
|
|
static const _kTheme = "cc_theme";
|
|
static const _kLocale = "cc_locale";
|
|
static const _kDateFormat = "cc_dateFormat";
|
|
static const _kTimeFormat = "cc_timeFormat";
|
|
static const _kWeekStart = "cc_weekStart";
|
|
static const _kCurrency = "cc_currency";
|
|
static const _kFontSize = "cc_fontSize";
|
|
|
|
String theme = "system"; // light | dark | system
|
|
String locale = "en-US"; // BCP-47 language-REGION
|
|
String dateFormat = "YMD"; // YMD | DMY_NUM | DMY | MDY
|
|
|
|
/// Which clock times are written on. "auto" is the chosen region's own
|
|
/// convention, which is what every time in the app read before there was a
|
|
/// setting; the other two are for the people whose region and habit disagree.
|
|
String timeFormat = "auto"; // auto | 24 | 12
|
|
|
|
/// The day a week is drawn as starting on, wherever weekdays are laid out in a
|
|
/// row — the charging scheduler's day picker today. See format.dart, which
|
|
/// owns the rule so every such row reads the same.
|
|
String weekStart = "auto"; // auto | monday | sunday
|
|
|
|
String currency = "USD"; // ISO 4217 code
|
|
String fontSize = "medium"; // small | medium | large
|
|
|
|
/// Language and region are two controls over the one stored tag, so the pair
|
|
/// can be mixed freely (English in Poland, say).
|
|
String get language => locale.split("-").first;
|
|
String get region => locale.split("-").length > 1 ? locale.split("-")[1] : "US";
|
|
|
|
Future<void> loadFromStorage() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
theme = prefs.getString(_kTheme) ?? theme;
|
|
locale = prefs.getString(_kLocale) ?? locale;
|
|
dateFormat = prefs.getString(_kDateFormat) ?? dateFormat;
|
|
timeFormat = prefs.getString(_kTimeFormat) ?? timeFormat;
|
|
weekStart = prefs.getString(_kWeekStart) ?? weekStart;
|
|
currency = prefs.getString(_kCurrency) ?? currency;
|
|
fontSize = prefs.getString(_kFontSize) ?? fontSize;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<void> _persist() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString(_kTheme, theme);
|
|
await prefs.setString(_kLocale, locale);
|
|
await prefs.setString(_kDateFormat, dateFormat);
|
|
await prefs.setString(_kTimeFormat, timeFormat);
|
|
await prefs.setString(_kWeekStart, weekStart);
|
|
await prefs.setString(_kCurrency, currency);
|
|
await prefs.setString(_kFontSize, fontSize);
|
|
}
|
|
|
|
/// Sync from a freshly fetched profile (login, boot, settings saves).
|
|
void applyFromProfile(UserProfile p) {
|
|
theme = p.theme;
|
|
locale = p.locale;
|
|
dateFormat = p.dateFormat;
|
|
timeFormat = p.timeFormat;
|
|
weekStart = p.weekStart;
|
|
currency = p.currency;
|
|
fontSize = p.fontSize;
|
|
_persist();
|
|
notifyListeners();
|
|
}
|
|
|
|
/// Optimistically apply a single changed field (used by Settings so the UI
|
|
/// reacts instantly while the PATCH is in flight).
|
|
void patch({
|
|
String? theme,
|
|
String? locale,
|
|
String? dateFormat,
|
|
String? timeFormat,
|
|
String? weekStart,
|
|
String? currency,
|
|
String? fontSize,
|
|
}) {
|
|
if (theme != null) this.theme = theme;
|
|
if (locale != null) this.locale = locale;
|
|
if (dateFormat != null) this.dateFormat = dateFormat;
|
|
if (timeFormat != null) this.timeFormat = timeFormat;
|
|
if (weekStart != null) this.weekStart = weekStart;
|
|
if (currency != null) this.currency = currency;
|
|
if (fontSize != null) this.fontSize = fontSize;
|
|
_persist();
|
|
notifyListeners();
|
|
}
|
|
|
|
ThemeMode get themeMode => switch (theme) {
|
|
"light" => ThemeMode.light,
|
|
"dark" => ThemeMode.dark,
|
|
_ => ThemeMode.system,
|
|
};
|
|
|
|
double get textScale => switch (fontSize) {
|
|
"small" => 0.9375,
|
|
"large" => 1.125,
|
|
_ => 1.0,
|
|
};
|
|
}
|