Phone App: connected service, charging cost, a tab picker and data export
Both READMEs claimed web parity with data export/import as the only
omission. That was three gaps out of date: the car screen had no
connected-service tab, no per-car charging-cost tab, and no way to say what
a car's page shows - all three of which the web has had since the car view
became a property of the car rather than of the browser.
The tab bar was the thing blocking the rest. It was a fixed list of eight
Tab(text: "Information") literals, so it could neither grow a tab nor read
an arrangement, and it sat outside the translation system that the rest of
the app has used since b6bb6b1. It now builds from the car's own tabOrder
and hiddenTabs, and labels come from car.tabs.* like the web's.
Rather than retype four subtrees of strings in three languages, the shared
ones - car.*, settings.advanced, forms.charging, forms.import and the
common keys the phone was missing - are copied out of the Web App's own
language files, with the phone's existing wording winning every collision.
Polish and Danish therefore arrive complete and cannot drift between the
two apps. Only five strings are genuinely phone-only: the reorder hint, the
saved-file message, the open action and two validation lines.
The connected-service tab mirrors ProviderPanel: headline readings, the
offer to take a provider odometer that is ahead of the stored one, the
vehicle record, and one collapsible card per capability, rendered from the
server's flattened key/value pairs so a provider adding a field surfaces it
without touching this app. Two deliberate differences. The raw-payload
disclosure is dropped - Toyota's eight sections are megabytes of JSON on a
phone screen, and the flattened fields carry the same content. And the
readings cannot be dragged here, though a stored metricOrder is still
honoured, so an arrangement made on the web carries over.
The view picker takes the same line on gestures. The web rearranges by
dragging the tab bar itself and the Information rows themselves; on a touch
screen that gesture belongs to the tab bar, so both arrangements are made
in the picker with a handle instead, and hiddenTabs, hiddenFields, tabOrder
and fieldOrder all save in one PUT. The key catalogues live in
car_view_sheet.dart and mirror hideableCarTabs / arrangeableCarTabs /
hideableCarFields in cars.go, because the server rejects anything else.
arrangeKeys applies a partial stored order the way the API documents it: an
unknown key is dropped and an unnamed one follows the arranged ones, which
is what puts a tab added in a later release at the end of somebody's page
rather than the middle of it.
Charging cost is the electric twin of Fuel and is built as one - the same
stats panel, tile and form shape, measured between full charges. It is the
per-car cost log, not the Charging section in the bottom bar, which remains
the charger network and OCPP control.
Export and import needed a phone answer to two browser affordances. The
export is written to the app's documents directory under the filename the
server's Content-Disposition names, and offered to whatever opens JSON via
open_filex - the same route attachments already take. The import goes
through the system file picker, validates the file locally, and confirms
with the number of cars the file actually holds, because the server always
creates new records and never merges.
The one field worth calling out on the client: _carPayload still leaves the
provider link and the view arrangement out, matching carPayload in
records.go, so saving the car form cannot silently unlink a car or undo an
arrangement.
Known gap, deliberately not closed here: the older sheets in
record_form_sheets.dart and most of car_detail_screen.dart still carry
hardcoded English. Everything added here and every tab label goes through
t(), but translating the rest of the car screen is its own change and would
have buried this one.
Verified by flutter analyze (clean), flutter test - 13 pass, 6 of them new,
covering arrangeKeys against partial, unknown and duplicate keys, the
charging models keeping uncomputed figures null rather than a plausible
zero, the new Car fields, and ProviderSnapshot parsing an unreachable
provider as an answer rather than a failure - and flutter build apk
--debug, which succeeds. The Kotlin Gradle plugin warnings in that build
are pre-existing.
Not verified: nothing was run against a live API Server or on a device, so
the new screens have not been driven end to end - only compiled, analyzed
and unit-tested.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
215c027ada
commit
e249c2f4d8
@@ -1,12 +1,15 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
import "../api.dart";
|
||||
import "../i18n.dart";
|
||||
import "../main.dart";
|
||||
import "../models.dart";
|
||||
import "../format.dart";
|
||||
import "../theme.dart";
|
||||
import "../widgets/attachment_field.dart";
|
||||
import "car_form_sheet.dart";
|
||||
import "car_view_sheet.dart";
|
||||
import "provider_tab.dart";
|
||||
import "record_form_sheets.dart";
|
||||
|
||||
/// Serializes a car to the full update payload. The API's updateCar rewrites
|
||||
@@ -48,10 +51,17 @@ class _CarDetailData {
|
||||
final List<MaintenanceEntry> maintenance;
|
||||
final List<FuelEntry> fuel;
|
||||
final FuelStats fuelStats;
|
||||
final List<ChargingSession> charging;
|
||||
final ChargingStats chargingStats;
|
||||
final List<CarDocument> documents;
|
||||
final List<Part> parts;
|
||||
final List<Reminder> reminders;
|
||||
|
||||
/// The manufacturer services this user has connected. Only read to decide
|
||||
/// whether the connected-service tab is on offer for a car that has no link
|
||||
/// yet — the tab loads its own data once it is open.
|
||||
final List<VehicleProvider> providers;
|
||||
|
||||
_CarDetailData({
|
||||
required this.car,
|
||||
required this.services,
|
||||
@@ -59,9 +69,12 @@ class _CarDetailData {
|
||||
required this.maintenance,
|
||||
required this.fuel,
|
||||
required this.fuelStats,
|
||||
required this.charging,
|
||||
required this.chargingStats,
|
||||
required this.documents,
|
||||
required this.parts,
|
||||
required this.reminders,
|
||||
required this.providers,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,9 +98,15 @@ class _CarDetailScreenState extends State<CarDetailScreen> {
|
||||
apiClient.listCarMaintenance(widget.carId),
|
||||
apiClient.listCarFuelEntries(widget.carId),
|
||||
apiClient.getCarFuelStats(widget.carId),
|
||||
apiClient.listCarChargingSessions(widget.carId),
|
||||
apiClient.getCarChargingStats(widget.carId),
|
||||
apiClient.listCarDocuments(widget.carId),
|
||||
apiClient.listCarParts(widget.carId),
|
||||
apiClient.listCarReminders(widget.carId),
|
||||
// Only decides whether one tab is offered, so it must not be able to take
|
||||
// the whole page down with it — a provider plugin that is misconfigured
|
||||
// (or a server too old to know the endpoint) leaves the tab off instead.
|
||||
apiClient.listVehicleProviders().catchError((_) => <VehicleProvider>[]),
|
||||
]);
|
||||
return _CarDetailData(
|
||||
car: results[0] as Car,
|
||||
@@ -96,9 +115,12 @@ class _CarDetailScreenState extends State<CarDetailScreen> {
|
||||
maintenance: results[3] as List<MaintenanceEntry>,
|
||||
fuel: results[4] as List<FuelEntry>,
|
||||
fuelStats: results[5] as FuelStats,
|
||||
documents: results[6] as List<CarDocument>,
|
||||
parts: results[7] as List<Part>,
|
||||
reminders: results[8] as List<Reminder>,
|
||||
charging: results[6] as List<ChargingSession>,
|
||||
chargingStats: results[7] as ChargingStats,
|
||||
documents: results[8] as List<CarDocument>,
|
||||
parts: results[9] as List<Part>,
|
||||
reminders: results[10] as List<Reminder>,
|
||||
providers: results[11] as List<VehicleProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -304,8 +326,15 @@ class _CarDetailScreenState extends State<CarDetailScreen> {
|
||||
final latest = data.services.isNotEmpty ? data.services.first : null;
|
||||
final status = serviceStatus(latest, car);
|
||||
|
||||
final tabKeys = _tabKeys(car, data.providers);
|
||||
|
||||
return DefaultTabController(
|
||||
length: 8,
|
||||
// The tab set is a property of the car: the view picker switches
|
||||
// tabs off, and linking a provider adds one. Keying the controller
|
||||
// on it rebuilds the controller instead of leaving it addressing a
|
||||
// length that no longer exists.
|
||||
key: ValueKey(tabKeys.join("/")),
|
||||
length: tabKeys.length,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(car.name),
|
||||
@@ -316,6 +345,12 @@ class _CarDetailScreenState extends State<CarDetailScreen> {
|
||||
icon: const Icon(Icons.person_add_alt),
|
||||
onPressed: () => _shareCar(car),
|
||||
),
|
||||
if (car.canWrite)
|
||||
IconButton(
|
||||
tooltip: t("car.viewPicker.open"),
|
||||
icon: const Icon(Icons.tune),
|
||||
onPressed: () => _openViewPicker(car, data.providers),
|
||||
),
|
||||
if (car.canWrite)
|
||||
IconButton(
|
||||
tooltip: "Edit car",
|
||||
@@ -336,18 +371,11 @@ class _CarDetailScreenState extends State<CarDetailScreen> {
|
||||
_deleteCar(car, data.services.length, data.parts.length),
|
||||
),
|
||||
],
|
||||
// Same order as the web app's CarDetail tabs.
|
||||
bottom: const TabBar(
|
||||
bottom: TabBar(
|
||||
isScrollable: true,
|
||||
tabs: [
|
||||
Tab(text: "Information"),
|
||||
Tab(text: "Service history"),
|
||||
Tab(text: "Technical check history"),
|
||||
Tab(text: "Maintenance"),
|
||||
Tab(text: "Fuel"),
|
||||
Tab(text: "Documents"),
|
||||
Tab(text: "Parts catalog"),
|
||||
Tab(text: "Reminders"),
|
||||
for (final key in tabKeys)
|
||||
Tab(text: _tabLabel(key, car, data.providers)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -367,144 +395,7 @@ class _CarDetailScreenState extends State<CarDetailScreen> {
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
children: [
|
||||
// Information tab
|
||||
_InfoTab(car: car, latest: latest),
|
||||
// Service history tab
|
||||
_TabList(
|
||||
empty: data.services.isEmpty ? "No service records yet." : null,
|
||||
onAdd: car.canWrite ? () => _addService(car) : null,
|
||||
addLabel: "Add service",
|
||||
children: data.services
|
||||
.map((s) => _ServiceTile(
|
||||
record: s,
|
||||
onEdit: car.canWrite ? () => _editService(car, s) : null,
|
||||
onDelete: car.canWrite ? () => _deleteService(s) : null,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
// Technical check history tab
|
||||
_TabList(
|
||||
empty: data.technicalChecks.isEmpty ? "No technical checks yet." : null,
|
||||
onAdd: car.canWrite
|
||||
? () => _sheet(TechnicalCheckSheet(carId: car.id, car: car))
|
||||
: null,
|
||||
addLabel: "Add check",
|
||||
children: data.technicalChecks
|
||||
.map((c) => _TechnicalCheckTile(
|
||||
check: c,
|
||||
onEdit: car.canWrite
|
||||
? () => _sheet(
|
||||
TechnicalCheckSheet(carId: car.id, car: car, check: c))
|
||||
: null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord("technical check",
|
||||
() => apiClient.deleteTechnicalCheck(c.id))
|
||||
: null,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
// Maintenance tab
|
||||
_TabList(
|
||||
empty: data.maintenance.isEmpty ? "No workshop visits yet." : null,
|
||||
onAdd:
|
||||
car.canWrite ? () => _sheet(MaintenanceSheet(carId: car.id)) : null,
|
||||
addLabel: "Log visit",
|
||||
children: data.maintenance
|
||||
.map((m) => _MaintenanceTile(
|
||||
entry: m,
|
||||
onEdit: car.canWrite
|
||||
? () => _sheet(MaintenanceSheet(carId: car.id, entry: m))
|
||||
: null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord("workshop visit",
|
||||
() => apiClient.deleteMaintenance(m.id))
|
||||
: null,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
// Fuel tab — the stats panel sits above the refill list.
|
||||
_TabList(
|
||||
empty: null,
|
||||
onAdd: car.canWrite ? () => _sheet(FuelSheet(carId: car.id)) : null,
|
||||
addLabel: "Log refill",
|
||||
children: [
|
||||
_FuelStatsPanel(stats: data.fuelStats),
|
||||
const SizedBox(height: 8),
|
||||
if (data.fuel.isEmpty)
|
||||
const _Empty("No refills yet.")
|
||||
else
|
||||
...data.fuel.reversed.map((f) => _FuelTile(
|
||||
entry: f,
|
||||
onEdit: car.canWrite
|
||||
? () => _sheet(FuelSheet(carId: car.id, entry: f))
|
||||
: null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord(
|
||||
"refill", () => apiClient.deleteFuelEntry(f.id))
|
||||
: null,
|
||||
)),
|
||||
],
|
||||
),
|
||||
// Documents tab
|
||||
_TabList(
|
||||
empty: data.documents.isEmpty ? "No documents yet." : null,
|
||||
onAdd: car.canWrite ? () => _sheet(DocumentSheet(carId: car.id)) : null,
|
||||
addLabel: "Add document",
|
||||
children: data.documents
|
||||
.map((d) => _DocumentTile(
|
||||
doc: d,
|
||||
onEdit: car.canWrite
|
||||
? () => _sheet(DocumentSheet(carId: car.id, doc: d))
|
||||
: null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord(
|
||||
"document", () => apiClient.deleteDocument(d.id))
|
||||
: null,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
// Parts catalog tab
|
||||
_TabList(
|
||||
empty: data.parts.isEmpty ? "No parts yet." : null,
|
||||
onAdd: car.canWrite ? () => _addPart(car) : null,
|
||||
addLabel: "Add part",
|
||||
children: data.parts
|
||||
.map((p) => _PartTile(
|
||||
part: p,
|
||||
onEdit: car.canWrite ? () => _editPart(car, p) : null,
|
||||
onDelete: car.canWrite ? () => _deletePart(p) : null,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
// Reminders tab
|
||||
_TabList(
|
||||
empty: data.reminders.isEmpty ? "No reminders yet." : null,
|
||||
onAdd: car.canWrite
|
||||
? () => _sheet(ReminderSheet(carId: car.id, car: car))
|
||||
: null,
|
||||
addLabel: "Add reminder",
|
||||
children: data.reminders
|
||||
.map((r) => _ReminderTile(
|
||||
reminder: r,
|
||||
// Auto reminders are derived from a document or
|
||||
// service record, so they are read-only here —
|
||||
// edit the record they came from instead.
|
||||
onEdit: car.canWrite && !r.auto
|
||||
? () => _sheet(
|
||||
ReminderSheet(carId: car.id, car: car, reminder: r))
|
||||
: null,
|
||||
onDelete: car.canWrite && !r.auto
|
||||
? () => _deleteRecord(
|
||||
"reminder", () => apiClient.deleteReminder(r.id))
|
||||
: null,
|
||||
onComplete: car.canWrite && !r.auto && !r.done
|
||||
? () => _completeReminder(r)
|
||||
: null,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
children: [for (final key in tabKeys) _tabBody(key, data)],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -515,6 +406,221 @@ class _CarDetailScreenState extends State<CarDetailScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// --- which tabs this car shows -------------------------------------------
|
||||
|
||||
/// Whether the connected-service tab is on offer. It shows for a linked car,
|
||||
/// and also for an unlinked one as long as this user has some manufacturer
|
||||
/// account connected — that is where the tab offers to link it. A user with
|
||||
/// nothing connected never sees the tab at all.
|
||||
bool _showProviderTab(Car car, List<VehicleProvider> providers) =>
|
||||
car.provider.isNotEmpty || providers.any((p) => p.connected);
|
||||
|
||||
/// The linked provider's display name ("MyToyota"), falling back to the raw
|
||||
/// plugin name and then to the generic tab label.
|
||||
String _providerLabel(Car car, List<VehicleProvider> providers) {
|
||||
for (final p in providers) {
|
||||
if (p.id == car.provider) return p.label;
|
||||
}
|
||||
return car.provider.isEmpty ? t("car.tabs.connected") : car.provider;
|
||||
}
|
||||
|
||||
/// The tabs to show, in this car's arrangement: its stored order applied to
|
||||
/// the catalogue, minus the ones switched off, minus the connected service
|
||||
/// when it does not apply.
|
||||
List<String> _tabKeys(Car car, List<VehicleProvider> providers) =>
|
||||
arrangeKeys(kCarTabKeys, car.tabOrder)
|
||||
.where((key) => !car.hiddenTabs.contains(key))
|
||||
.where((key) => key != "provider" || _showProviderTab(car, providers))
|
||||
.toList();
|
||||
|
||||
String _tabLabel(String key, Car car, List<VehicleProvider> providers) =>
|
||||
key == "provider" ? _providerLabel(car, providers) : t("car.tabs.$key");
|
||||
|
||||
Future<void> _openViewPicker(Car car, List<VehicleProvider> providers) async {
|
||||
final updated = await showModalBottomSheet<Car>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (_) => CarViewSheet(
|
||||
car: car,
|
||||
showProvider: _showProviderTab(car, providers),
|
||||
providerLabel: car.provider.isEmpty ? "" : _providerLabel(car, providers),
|
||||
),
|
||||
);
|
||||
if (updated != null) _reload();
|
||||
}
|
||||
|
||||
/// One tab's content, by key. The keys are the web app's, so the two apps
|
||||
/// cannot drift on what a stored arrangement means.
|
||||
Widget _tabBody(String key, _CarDetailData data) {
|
||||
final car = data.car;
|
||||
final latest = data.services.isNotEmpty ? data.services.first : null;
|
||||
|
||||
switch (key) {
|
||||
case "provider":
|
||||
return ProviderTab(car: car, onCarUpdated: (_) => _reload());
|
||||
|
||||
case "info":
|
||||
return _InfoTab(car: car, latest: latest);
|
||||
|
||||
case "services":
|
||||
return _TabList(
|
||||
empty: data.services.isEmpty ? "No service records yet." : null,
|
||||
onAdd: car.canWrite ? () => _addService(car) : null,
|
||||
addLabel: "Add service",
|
||||
children: data.services
|
||||
.map((s) => _ServiceTile(
|
||||
record: s,
|
||||
onEdit: car.canWrite ? () => _editService(car, s) : null,
|
||||
onDelete: car.canWrite ? () => _deleteService(s) : null,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
case "technical":
|
||||
return _TabList(
|
||||
empty: data.technicalChecks.isEmpty ? "No technical checks yet." : null,
|
||||
onAdd: car.canWrite ? () => _sheet(TechnicalCheckSheet(carId: car.id, car: car)) : null,
|
||||
addLabel: "Add check",
|
||||
children: data.technicalChecks
|
||||
.map((c) => _TechnicalCheckTile(
|
||||
check: c,
|
||||
onEdit: car.canWrite
|
||||
? () => _sheet(TechnicalCheckSheet(carId: car.id, car: car, check: c))
|
||||
: null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord(
|
||||
"technical check", () => apiClient.deleteTechnicalCheck(c.id))
|
||||
: null,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
case "maintenance":
|
||||
return _TabList(
|
||||
empty: data.maintenance.isEmpty ? "No workshop visits yet." : null,
|
||||
onAdd: car.canWrite ? () => _sheet(MaintenanceSheet(carId: car.id)) : null,
|
||||
addLabel: "Log visit",
|
||||
children: data.maintenance
|
||||
.map((m) => _MaintenanceTile(
|
||||
entry: m,
|
||||
onEdit: car.canWrite
|
||||
? () => _sheet(MaintenanceSheet(carId: car.id, entry: m))
|
||||
: null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord(
|
||||
"workshop visit", () => apiClient.deleteMaintenance(m.id))
|
||||
: null,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
// The stats panel sits above the refill list.
|
||||
case "fuel":
|
||||
return _TabList(
|
||||
empty: null,
|
||||
onAdd: car.canWrite ? () => _sheet(FuelSheet(carId: car.id)) : null,
|
||||
addLabel: "Log refill",
|
||||
children: [
|
||||
_FuelStatsPanel(stats: data.fuelStats),
|
||||
const SizedBox(height: 8),
|
||||
if (data.fuel.isEmpty)
|
||||
const _Empty("No refills yet.")
|
||||
else
|
||||
...data.fuel.reversed.map((f) => _FuelTile(
|
||||
entry: f,
|
||||
onEdit: car.canWrite ? () => _sheet(FuelSheet(carId: car.id, entry: f)) : null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord("refill", () => apiClient.deleteFuelEntry(f.id))
|
||||
: null,
|
||||
)),
|
||||
],
|
||||
);
|
||||
|
||||
// The electric twin of the fuel tab, laid out the same way.
|
||||
case "charging":
|
||||
return _TabList(
|
||||
empty: null,
|
||||
onAdd: car.canWrite ? () => _sheet(ChargingSheet(carId: car.id)) : null,
|
||||
addLabel: t("car.charging.add"),
|
||||
children: [
|
||||
_ChargingStatsPanel(stats: data.chargingStats),
|
||||
const SizedBox(height: 8),
|
||||
if (data.charging.isEmpty)
|
||||
_Empty(t("car.charging.empty"))
|
||||
else
|
||||
...data.charging.reversed.map((c) => _ChargingTile(
|
||||
entry: c,
|
||||
onEdit: car.canWrite
|
||||
? () => _sheet(ChargingSheet(carId: car.id, entry: c))
|
||||
: null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord(
|
||||
"charge", () => apiClient.deleteChargingSession(c.id))
|
||||
: null,
|
||||
)),
|
||||
],
|
||||
);
|
||||
|
||||
case "documents":
|
||||
return _TabList(
|
||||
empty: data.documents.isEmpty ? "No documents yet." : null,
|
||||
onAdd: car.canWrite ? () => _sheet(DocumentSheet(carId: car.id)) : null,
|
||||
addLabel: "Add document",
|
||||
children: data.documents
|
||||
.map((d) => _DocumentTile(
|
||||
doc: d,
|
||||
onEdit:
|
||||
car.canWrite ? () => _sheet(DocumentSheet(carId: car.id, doc: d)) : null,
|
||||
onDelete: car.canWrite
|
||||
? () => _deleteRecord("document", () => apiClient.deleteDocument(d.id))
|
||||
: null,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
case "parts":
|
||||
return _TabList(
|
||||
empty: data.parts.isEmpty ? "No parts yet." : null,
|
||||
onAdd: car.canWrite ? () => _addPart(car) : null,
|
||||
addLabel: "Add part",
|
||||
children: data.parts
|
||||
.map((p) => _PartTile(
|
||||
part: p,
|
||||
onEdit: car.canWrite ? () => _editPart(car, p) : null,
|
||||
onDelete: car.canWrite ? () => _deletePart(p) : null,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
case "reminders":
|
||||
return _TabList(
|
||||
empty: data.reminders.isEmpty ? "No reminders yet." : null,
|
||||
onAdd: car.canWrite ? () => _sheet(ReminderSheet(carId: car.id, car: car)) : null,
|
||||
addLabel: "Add reminder",
|
||||
children: data.reminders
|
||||
.map((r) => _ReminderTile(
|
||||
reminder: r,
|
||||
// Auto reminders are derived from a document or service
|
||||
// record, so they are read-only here — edit the record they
|
||||
// came from instead.
|
||||
onEdit: car.canWrite && !r.auto
|
||||
? () => _sheet(ReminderSheet(carId: car.id, car: car, reminder: r))
|
||||
: null,
|
||||
onDelete: car.canWrite && !r.auto
|
||||
? () => _deleteRecord("reminder", () => apiClient.deleteReminder(r.id))
|
||||
: null,
|
||||
onComplete: car.canWrite && !r.auto && !r.done
|
||||
? () => _completeReminder(r)
|
||||
: null,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
// Unreachable for the keys above; a key from a newer release reaching an
|
||||
// older build lands here rather than taking the page down.
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
/// A scrollable tab body: an optional "+ Add" button, an empty-state message, or
|
||||
@@ -591,13 +697,44 @@ class _StatusHeader extends StatelessWidget {
|
||||
|
||||
/// Information tab: the car's spec details (oil specs, odometer, interval, next
|
||||
/// due, VIN) in a scrollable card.
|
||||
///
|
||||
/// Which rows show and in which order belongs to the car, not to this device —
|
||||
/// everyone it is shared with sees the same page. Both are edited in the view
|
||||
/// picker (see [CarViewSheet]).
|
||||
class _InfoTab extends StatelessWidget {
|
||||
final Car car;
|
||||
final ServiceRecord? latest;
|
||||
const _InfoTab({required this.car, required this.latest});
|
||||
|
||||
/// Every row this tab can show, by the key the car's arrangement names it by.
|
||||
/// Keys mirror hideableCarFields in the API's cars.go and car.info.* in the
|
||||
/// translation files.
|
||||
Map<String, String> _values() => {
|
||||
"oilSpec": _orDash(car.oilSpec),
|
||||
"transmissionOil": _orDash(car.transmissionOilSpec),
|
||||
"differentialOil": _orDash(car.differentialOilSpec),
|
||||
"brakeFluid": _orDash(car.brakeFluidSpec),
|
||||
"coolant": _orDash(car.coolantSpec),
|
||||
"odometer": formatKm(car.currentKm),
|
||||
"serviceInterval":
|
||||
"${car.serviceIntervalDays} days · ${formatKm(car.serviceIntervalKm)}",
|
||||
"nextDue":
|
||||
"${formatDate(latest?.nextServiceDate)} · ${formatKm(latest?.nextServiceKm)}",
|
||||
"registrationPlate": _orDash(car.registration),
|
||||
"registrationCountry": _orDash(car.registrationCountry),
|
||||
"vin": _orDash(car.vin),
|
||||
"fuelType": _fuelLabel(car.fuelType),
|
||||
"buildDate": _dateOrDash(car.buildDate),
|
||||
"firstRegistration": _dateOrDash(car.firstRegistrationDate),
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final values = _values();
|
||||
final keys = arrangeKeys(kCarInfoFieldKeys, car.fieldOrder)
|
||||
.where((key) => !car.hiddenFields.contains(key))
|
||||
.toList();
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 80),
|
||||
children: [
|
||||
@@ -612,22 +749,22 @@ class _InfoTab extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_kv(context, "Engine oil spec", _orDash(car.oilSpec)),
|
||||
_kv(context, "Transmission oil spec", _orDash(car.transmissionOilSpec)),
|
||||
_kv(context, "Differential oil spec", _orDash(car.differentialOilSpec)),
|
||||
_kv(context, "Brake fluid spec", _orDash(car.brakeFluidSpec)),
|
||||
_kv(context, "Coolant spec", _orDash(car.coolantSpec)),
|
||||
_kv(context, "Current odometer", formatKm(car.currentKm)),
|
||||
_kv(context, "Service interval", "${car.serviceIntervalDays} days · ${formatKm(car.serviceIntervalKm)}"),
|
||||
_kv(context, "Technical check interval",
|
||||
"${car.technicalCheckIntervalDays > 0 ? car.technicalCheckIntervalDays : 365} days"),
|
||||
_kv(context, "Next due", "${formatDate(latest?.nextServiceDate)} · ${formatKm(latest?.nextServiceKm)}"),
|
||||
_kv(context, "Registration plate", _orDash(car.registration)),
|
||||
_kv(context, "Registration country", _orDash(car.registrationCountry)),
|
||||
_kv(context, "VIN", _orDash(car.vin)),
|
||||
_kv(context, "Fuel type", _fuelLabel(car.fuelType)),
|
||||
_kv(context, "Build date", _dateOrDash(car.buildDate)),
|
||||
_kv(context, "First registration", _dateOrDash(car.firstRegistrationDate)),
|
||||
if (keys.isEmpty)
|
||||
Text(t("car.info.allHidden"),
|
||||
style: TextStyle(color: DriverVault.muted(context)))
|
||||
else
|
||||
for (final key in keys) ...[
|
||||
_kv(context, t("car.info.$key"), values[key] ?? "—"),
|
||||
// The roadworthiness cycle is the car's other interval, and
|
||||
// reads as a footnote to the service one rather than a row
|
||||
// of its own — so it follows it, and goes when it goes.
|
||||
if (key == "serviceInterval")
|
||||
_kv(
|
||||
context,
|
||||
t("car.info.technicalCheckInterval"),
|
||||
"${car.technicalCheckIntervalDays > 0 ? car.technicalCheckIntervalDays : 365} days",
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1082,6 +1219,145 @@ class _FuelStatsPanel extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// The charging summary, the electric twin of [_FuelStatsPanel]. Same caveat on
|
||||
/// the tracked distance: it covers the full-charge windows only.
|
||||
class _ChargingStatsPanel extends StatelessWidget {
|
||||
final ChargingStats stats;
|
||||
const _ChargingStatsPanel({required this.stats});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (stats.entries == 0) return const SizedBox.shrink();
|
||||
return _RecordCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(t("car.charging.title"), style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 16,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_stat(context, t("car.charging.average"),
|
||||
formatKwhConsumption(stats.avgConsumptionKwh100)),
|
||||
_stat(context, t("car.charging.best"),
|
||||
formatKwhConsumption(stats.bestConsumptionKwh100)),
|
||||
_stat(context, t("car.charging.worst"),
|
||||
formatKwhConsumption(stats.worstConsumptionKwh100)),
|
||||
_stat(context, t("car.charging.average"), formatKmPerKwh(stats.avgKmPerKwh)),
|
||||
_stat(context, t("car.charging.costPerKm"), formatMoney(stats.costPerKm)),
|
||||
_stat(context, t("car.charging.colPerKwh"), formatMoney(stats.avgPricePerKwh)),
|
||||
_stat(context, t("car.charging.totalKwh"), formatKwh(stats.totalKwh)),
|
||||
_stat(context, t("car.charging.totalSpent"), formatMoney(stats.totalCost)),
|
||||
_stat(context, t("car.charging.sessions"), "${stats.entries}"),
|
||||
_stat(context, t("car.charging.trackedDistance"), formatKm(stats.trackedDistanceKm)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Without this the tracked distance reads as a mistake whenever the
|
||||
// history starts or ends on a partial charge.
|
||||
_sub(context, t("car.charging.subtitle")),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _stat(BuildContext context, String label, String value) => SizedBox(
|
||||
width: 150,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: TextStyle(fontSize: 11, color: DriverVault.muted(context))),
|
||||
Text(value,
|
||||
style: DriverVault.mono(context,
|
||||
size: 13,
|
||||
weight: FontWeight.w600,
|
||||
color: Theme.of(context).colorScheme.onSurface)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _ChargingTile extends StatelessWidget {
|
||||
final ChargingSession entry;
|
||||
final VoidCallback? onEdit;
|
||||
final VoidCallback? onDelete;
|
||||
const _ChargingTile({required this.entry, this.onEdit, this.onDelete});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _RecordCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(formatDate(entry.date), style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
Row(children: [
|
||||
Text(formatKm(entry.km), style: const TextStyle(fontSize: 13)),
|
||||
if (onEdit != null || onDelete != null)
|
||||
_RowMenu(onEdit: onEdit, onDelete: onDelete),
|
||||
]),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
_sub(
|
||||
context,
|
||||
[
|
||||
formatKwh(entry.kwh),
|
||||
if (entry.cost > 0) formatMoney(entry.cost),
|
||||
if (entry.pricePerKwh != null)
|
||||
"${entry.pricePerKwh!.toStringAsFixed(3)}/kWh",
|
||||
].join(" · ")),
|
||||
const SizedBox(height: 6),
|
||||
Wrap(spacing: 6, runSpacing: 6, children: [
|
||||
_tag(context, entry.fullCharge ? t("forms.charging.fullCharge") : t("car.charging.partial"),
|
||||
muted: !entry.fullCharge),
|
||||
if (entry.missedSession) _tag(context, t("car.charging.gap"), warn: true),
|
||||
if (entry.location.isNotEmpty) _tag(context, entry.location, muted: true),
|
||||
]),
|
||||
// Consumption exists only on a full charge that closes a computable
|
||||
// window; anything else has nothing to report.
|
||||
if (entry.consumptionKwh100 != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
"${formatKwhConsumption(entry.consumptionKwh100)} · ${formatKmPerKwh(entry.kmPerKwh)}"
|
||||
" over ${formatKm(entry.distanceKm)}",
|
||||
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
_AttachmentLine(path: "/charging-sessions", id: entry.id, record: entry),
|
||||
if (entry.notes.isNotEmpty) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(entry.notes, style: const TextStyle(fontSize: 12, fontStyle: FontStyle.italic)),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tag(BuildContext context, String label, {bool muted = false, bool warn = false}) {
|
||||
final dark = DriverVault.isDark(context);
|
||||
final Color bg, fg;
|
||||
if (warn) {
|
||||
bg = dark ? DriverVault.warningSoftDark : DriverVault.warningSoft;
|
||||
fg = DriverVault.warning;
|
||||
} else if (muted) {
|
||||
bg = dark ? DriverVault.darkSunken : DriverVault.ink50;
|
||||
fg = DriverVault.muted(context);
|
||||
} else {
|
||||
bg = dark ? DriverVault.successSoftDark : DriverVault.successSoft;
|
||||
fg = DriverVault.success;
|
||||
}
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(6)),
|
||||
child: Text(label, style: TextStyle(fontSize: 11, color: fg, fontWeight: FontWeight.w600)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FuelTile extends StatelessWidget {
|
||||
final FuelEntry entry;
|
||||
final VoidCallback? onEdit;
|
||||
|
||||
Reference in New Issue
Block a user