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:
1 parent
215c027ada
commit
e249c2f4d8
14 files changed
+3510
-203
No files matched your search
@@ -14,6 +14,12 @@ double? _asDoubleOrNull(dynamic v) => v is num ? v.toDouble() : null;
|
||||
DateTime? _asDate(dynamic v) =>
|
||||
v == null ? null : DateTime.tryParse(v.toString())?.toLocal();
|
||||
|
||||
/// A JSON array of strings — the key sets a car carries for what its page shows
|
||||
/// and in which order. Absent or null reads as empty, which every consumer takes
|
||||
/// to mean "nothing hidden" / "the default order".
|
||||
List<String> _asStrList(dynamic v) =>
|
||||
v is List ? v.map(_asStr).where((s) => s.isNotEmpty).toList() : const [];
|
||||
|
||||
/// The single optional file a record carries — a receipt, a scan, a photo of a
|
||||
/// part's box. Mirrors the API's embedded Attachment: the bytes are never in the
|
||||
/// JSON, only whether there are any and what they were stored as. Fetch them
|
||||
@@ -71,6 +77,25 @@ class Car {
|
||||
/// (or any code that constructs a Car without it) stay fully editable.
|
||||
final String access;
|
||||
|
||||
/// The manufacturer service this car came from ("toyota") and that service's
|
||||
/// own id for the vehicle (the VIN, for Toyota). Both blank for a car entered
|
||||
/// by hand. Written only by the link/import endpoints, never by a car edit —
|
||||
/// which is why _carPayload leaves them out.
|
||||
final String provider;
|
||||
final String providerVehicleId;
|
||||
|
||||
/// What this car's page does not show, and the order it lays out what it
|
||||
/// does. Properties of the car, so everyone it is shared with sees the same
|
||||
/// page. The hidden sets rather than the visible ones, so a tab or field added
|
||||
/// in a later release is on by default; the orders may be partial, and any key
|
||||
/// they leave out follows the ones they name. Written only through
|
||||
/// PUT /cars/{id}/view.
|
||||
final List<String> hiddenTabs;
|
||||
final List<String> hiddenFields;
|
||||
final List<String> tabOrder;
|
||||
final List<String> fieldOrder;
|
||||
final List<String> metricOrder;
|
||||
|
||||
Car({
|
||||
required this.id,
|
||||
required this.name,
|
||||
@@ -93,6 +118,13 @@ class Car {
|
||||
this.technicalCheckIntervalDays = 0,
|
||||
required this.currentKm,
|
||||
this.access = "owner",
|
||||
this.provider = "",
|
||||
this.providerVehicleId = "",
|
||||
this.hiddenTabs = const [],
|
||||
this.hiddenFields = const [],
|
||||
this.tabOrder = const [],
|
||||
this.fieldOrder = const [],
|
||||
this.metricOrder = const [],
|
||||
});
|
||||
|
||||
factory Car.fromJson(Map<String, dynamic> j) => Car(
|
||||
@@ -117,6 +149,13 @@ class Car {
|
||||
technicalCheckIntervalDays: _asInt(j["technicalCheckIntervalDays"]),
|
||||
currentKm: _asInt(j["currentKm"]),
|
||||
access: j["access"] == null ? "owner" : _asStr(j["access"]),
|
||||
provider: _asStr(j["provider"]),
|
||||
providerVehicleId: _asStr(j["providerVehicleId"]),
|
||||
hiddenTabs: _asStrList(j["hiddenTabs"]),
|
||||
hiddenFields: _asStrList(j["hiddenFields"]),
|
||||
tabOrder: _asStrList(j["tabOrder"]),
|
||||
fieldOrder: _asStrList(j["fieldOrder"]),
|
||||
metricOrder: _asStrList(j["metricOrder"]),
|
||||
);
|
||||
|
||||
bool get isOwner => access == "owner";
|
||||
@@ -385,6 +424,132 @@ class FuelStats {
|
||||
);
|
||||
}
|
||||
|
||||
/// One charge of an EV — the electric counterpart of [FuelEntry], and derived
|
||||
/// the same way: consumption is measured between full charges, so a top-up
|
||||
/// counts towards the next full one. The server computes every figure below the
|
||||
/// raw kWh/cost and omits any it could not derive.
|
||||
class ChargingSession with HasAttachment {
|
||||
final String id;
|
||||
final String car;
|
||||
final DateTime? date;
|
||||
final int km;
|
||||
final double kwh;
|
||||
final double cost;
|
||||
|
||||
/// Taken to the car's usual full point — the reference the efficiency windows
|
||||
/// are measured between.
|
||||
final bool fullCharge;
|
||||
|
||||
/// The car was charged before this without being logged, so the odometer span
|
||||
/// is not accounted for by the kWh on record. Any window containing it is
|
||||
/// left uncomputed rather than reported as implausibly efficient.
|
||||
final bool missedSession;
|
||||
|
||||
final String location;
|
||||
final String notes;
|
||||
|
||||
final double? pricePerKwh;
|
||||
final int? distanceKm;
|
||||
final double? kwhUsed;
|
||||
final double? consumptionKwh100;
|
||||
final double? kmPerKwh;
|
||||
final double? costPerKm;
|
||||
@override
|
||||
final String fileName;
|
||||
@override
|
||||
final bool hasFile;
|
||||
|
||||
ChargingSession({
|
||||
required this.id,
|
||||
required this.car,
|
||||
required this.date,
|
||||
required this.km,
|
||||
required this.kwh,
|
||||
required this.cost,
|
||||
this.fullCharge = true,
|
||||
this.missedSession = false,
|
||||
this.location = "",
|
||||
this.notes = "",
|
||||
this.pricePerKwh,
|
||||
this.distanceKm,
|
||||
this.kwhUsed,
|
||||
this.consumptionKwh100,
|
||||
this.kmPerKwh,
|
||||
this.costPerKm,
|
||||
this.fileName = "",
|
||||
this.hasFile = false,
|
||||
});
|
||||
|
||||
factory ChargingSession.fromJson(Map<String, dynamic> j) => ChargingSession(
|
||||
id: _asStr(j["id"]),
|
||||
car: _asStr(j["car"]),
|
||||
date: _asDate(j["date"]),
|
||||
km: _asInt(j["km"]),
|
||||
kwh: _asDouble(j["kwh"]),
|
||||
cost: _asDouble(j["cost"]),
|
||||
fullCharge: _asBool(j["fullCharge"]),
|
||||
missedSession: _asBool(j["missedSession"]),
|
||||
location: _asStr(j["location"]),
|
||||
notes: _asStr(j["notes"]),
|
||||
pricePerKwh: _asDoubleOrNull(j["pricePerKwh"]),
|
||||
distanceKm: _asIntOrNull(j["distanceKm"]),
|
||||
kwhUsed: _asDoubleOrNull(j["kwhUsed"]),
|
||||
consumptionKwh100: _asDoubleOrNull(j["consumptionKwh100"]),
|
||||
kmPerKwh: _asDoubleOrNull(j["kmPerKwh"]),
|
||||
costPerKm: _asDoubleOrNull(j["costPerKm"]),
|
||||
fileName: _asStr(j["fileName"]),
|
||||
hasFile: _asBool(j["hasFile"]),
|
||||
);
|
||||
}
|
||||
|
||||
/// A summary of a car's whole charging history. [trackedDistanceKm] is the
|
||||
/// distance covered by computable full-charge windows — the same caveat as
|
||||
/// [FuelStats.trackedDistanceKm].
|
||||
class ChargingStats {
|
||||
final int entries;
|
||||
final double totalKwh;
|
||||
final double totalCost;
|
||||
final int trackedDistanceKm;
|
||||
final double? avgConsumptionKwh100;
|
||||
final double? bestConsumptionKwh100;
|
||||
final double? worstConsumptionKwh100;
|
||||
final double? avgKmPerKwh;
|
||||
final double? avgPricePerKwh;
|
||||
final double? costPerKm;
|
||||
final DateTime? firstDate;
|
||||
final DateTime? lastDate;
|
||||
|
||||
const ChargingStats({
|
||||
this.entries = 0,
|
||||
this.totalKwh = 0,
|
||||
this.totalCost = 0,
|
||||
this.trackedDistanceKm = 0,
|
||||
this.avgConsumptionKwh100,
|
||||
this.bestConsumptionKwh100,
|
||||
this.worstConsumptionKwh100,
|
||||
this.avgKmPerKwh,
|
||||
this.avgPricePerKwh,
|
||||
this.costPerKm,
|
||||
this.firstDate,
|
||||
this.lastDate,
|
||||
});
|
||||
|
||||
factory ChargingStats.fromJson(Map<String, dynamic> j) => ChargingStats(
|
||||
entries: _asInt(j["entries"]),
|
||||
totalKwh: _asDouble(j["totalKwh"]),
|
||||
totalCost: _asDouble(j["totalCost"]),
|
||||
trackedDistanceKm: _asInt(j["trackedDistanceKm"]),
|
||||
avgConsumptionKwh100: _asDoubleOrNull(j["avgConsumptionKwh100"]),
|
||||
bestConsumptionKwh100: _asDoubleOrNull(j["bestConsumptionKwh100"]),
|
||||
worstConsumptionKwh100: _asDoubleOrNull(j["worstConsumptionKwh100"]),
|
||||
avgKmPerKwh: _asDoubleOrNull(j["avgKmPerKwh"]),
|
||||
avgPricePerKwh: _asDoubleOrNull(j["avgPricePerKwh"]),
|
||||
costPerKm: _asDoubleOrNull(j["costPerKm"]),
|
||||
firstDate: _asDate(j["firstDate"]),
|
||||
lastDate: _asDate(j["lastDate"]),
|
||||
);
|
||||
}
|
||||
|
||||
/// One workshop visit or repair — work done outside the routine service
|
||||
/// schedule (which lives in [ServiceRecord]). A broken alternator replaced at a
|
||||
/// garage belongs here; the annual oil change does not.
|
||||
@@ -891,3 +1056,208 @@ class AnkerControl {
|
||||
|
||||
double get meterKwh => meterWh / 1000.0;
|
||||
}
|
||||
|
||||
// --- vehicle providers (the connected-service tab) ---------------------------
|
||||
//
|
||||
// A provider is a manufacturer service a car can be linked to (MyToyota today).
|
||||
// Nothing below models an upstream schema: the API Server flattens whatever the
|
||||
// plugin returned into key/value pairs, so a provider adding a field surfaces it
|
||||
// here without a change to this file. See the API's vehicleproviders.go.
|
||||
|
||||
/// One registered provider and whether this user can currently use it.
|
||||
/// [detail] says, in one sentence, what to do about a closed gate.
|
||||
class VehicleProvider {
|
||||
final String id;
|
||||
final String label; // "MyToyota"
|
||||
final String service; // "Toyota Connected Europe"
|
||||
final bool connected;
|
||||
final String detail;
|
||||
|
||||
const VehicleProvider({
|
||||
required this.id,
|
||||
required this.label,
|
||||
this.service = "",
|
||||
this.connected = false,
|
||||
this.detail = "",
|
||||
});
|
||||
|
||||
factory VehicleProvider.fromJson(Map<String, dynamic> j) => VehicleProvider(
|
||||
id: _asStr(j["id"]),
|
||||
label: _asStr(j["label"]),
|
||||
service: _asStr(j["service"]),
|
||||
connected: _asBool(j["connected"]),
|
||||
detail: _asStr(j["detail"]),
|
||||
);
|
||||
}
|
||||
|
||||
/// One leaf of a provider payload, flattened to a dotted path.
|
||||
class ProviderField {
|
||||
final String key;
|
||||
final String value;
|
||||
const ProviderField({required this.key, required this.value});
|
||||
|
||||
factory ProviderField.fromJson(Map<String, dynamic> j) =>
|
||||
ProviderField(key: _asStr(j["key"]), value: _asStr(j["value"]));
|
||||
|
||||
static List<ProviderField> listFrom(dynamic v) => v is List
|
||||
? v.map((e) => ProviderField.fromJson(Map<String, dynamic>.from(e))).toList()
|
||||
: const [];
|
||||
}
|
||||
|
||||
/// One vehicle on the user's provider account.
|
||||
class ProviderVehicle {
|
||||
final String id; // the provider's own id (the VIN, for Toyota)
|
||||
final String vin;
|
||||
final String name;
|
||||
final String make;
|
||||
final String model;
|
||||
final int year;
|
||||
final String imageUrl;
|
||||
final List<ProviderField> fields;
|
||||
|
||||
/// Set when this user already has a car linked to this vehicle, so the UI can
|
||||
/// say so instead of offering to link it twice.
|
||||
final String linkedCarId;
|
||||
|
||||
const ProviderVehicle({
|
||||
required this.id,
|
||||
this.vin = "",
|
||||
this.name = "",
|
||||
this.make = "",
|
||||
this.model = "",
|
||||
this.year = 0,
|
||||
this.imageUrl = "",
|
||||
this.fields = const [],
|
||||
this.linkedCarId = "",
|
||||
});
|
||||
|
||||
factory ProviderVehicle.fromJson(Map<String, dynamic> j) => ProviderVehicle(
|
||||
id: _asStr(j["id"]),
|
||||
vin: _asStr(j["vin"]),
|
||||
name: _asStr(j["name"]),
|
||||
make: _asStr(j["make"]),
|
||||
model: _asStr(j["model"]),
|
||||
year: _asInt(j["year"]),
|
||||
imageUrl: _asStr(j["imageUrl"]),
|
||||
fields: ProviderField.listFrom(j["fields"]),
|
||||
linkedCarId: _asStr(j["linkedCarId"]),
|
||||
);
|
||||
|
||||
String get subtitle =>
|
||||
[make, model, year > 0 ? "$year" : ""].where((s) => s.isNotEmpty).join(" ");
|
||||
}
|
||||
|
||||
/// A headline reading lifted out of the sections — the few values worth showing
|
||||
/// large. [key] is a stable id the app localizes (car.provider.metrics.*).
|
||||
class ProviderMetric {
|
||||
final String key;
|
||||
final String value;
|
||||
final String unit;
|
||||
const ProviderMetric({required this.key, required this.value, this.unit = ""});
|
||||
|
||||
factory ProviderMetric.fromJson(Map<String, dynamic> j) => ProviderMetric(
|
||||
key: _asStr(j["key"]),
|
||||
value: _asStr(j["value"]),
|
||||
unit: _asStr(j["unit"]),
|
||||
);
|
||||
}
|
||||
|
||||
/// One capability's outcome. A section that fails carries its error and the rest
|
||||
/// still render: half a snapshot beats an error page.
|
||||
class ProviderSection {
|
||||
final String id;
|
||||
final String status; // ok | error | empty
|
||||
final String error;
|
||||
final List<ProviderField> fields;
|
||||
final bool truncated;
|
||||
|
||||
const ProviderSection({
|
||||
required this.id,
|
||||
this.status = "ok",
|
||||
this.error = "",
|
||||
this.fields = const [],
|
||||
this.truncated = false,
|
||||
});
|
||||
|
||||
factory ProviderSection.fromJson(Map<String, dynamic> j) => ProviderSection(
|
||||
id: _asStr(j["id"]),
|
||||
status: _asStr(j["status"]).isEmpty ? "ok" : _asStr(j["status"]),
|
||||
error: _asStr(j["error"]),
|
||||
fields: ProviderField.listFrom(j["fields"]),
|
||||
truncated: _asBool(j["truncated"]),
|
||||
);
|
||||
}
|
||||
|
||||
/// Everything a provider can currently tell us about one car.
|
||||
///
|
||||
/// [unavailable] replaces the payload when the provider cannot be reached for
|
||||
/// this car at all — not connected, or the vehicle is not on *this* user's
|
||||
/// account. It arrives as a 200, because "we asked and here is why there is
|
||||
/// nothing" is an answer rather than a failure.
|
||||
class ProviderSnapshot {
|
||||
final String provider;
|
||||
final String label;
|
||||
final String service;
|
||||
final bool unavailable;
|
||||
final String detail;
|
||||
final DateTime? fetchedAt;
|
||||
final ProviderVehicle? vehicle;
|
||||
final List<ProviderMetric> metrics;
|
||||
final List<ProviderSection> sections;
|
||||
|
||||
/// The odometer the provider reports when it is ahead of the car's stored
|
||||
/// reading — what the tab's "update odometer" offers. 0 when they agree.
|
||||
final int suggestedCurrentKm;
|
||||
|
||||
const ProviderSnapshot({
|
||||
this.provider = "",
|
||||
this.label = "",
|
||||
this.service = "",
|
||||
this.unavailable = false,
|
||||
this.detail = "",
|
||||
this.fetchedAt,
|
||||
this.vehicle,
|
||||
this.metrics = const [],
|
||||
this.sections = const [],
|
||||
this.suggestedCurrentKm = 0,
|
||||
});
|
||||
|
||||
factory ProviderSnapshot.fromJson(Map<String, dynamic> j) {
|
||||
final v = j["vehicle"];
|
||||
return ProviderSnapshot(
|
||||
provider: _asStr(j["provider"]),
|
||||
label: _asStr(j["label"]),
|
||||
service: _asStr(j["service"]),
|
||||
unavailable: _asBool(j["unavailable"]),
|
||||
detail: _asStr(j["detail"]),
|
||||
fetchedAt: _asDate(j["fetchedAt"]),
|
||||
vehicle: v is Map ? ProviderVehicle.fromJson(Map<String, dynamic>.from(v)) : null,
|
||||
metrics: j["metrics"] is List
|
||||
? (j["metrics"] as List)
|
||||
.map((e) => ProviderMetric.fromJson(Map<String, dynamic>.from(e)))
|
||||
.toList()
|
||||
: const [],
|
||||
sections: j["sections"] is List
|
||||
? (j["sections"] as List)
|
||||
.map((e) => ProviderSection.fromJson(Map<String, dynamic>.from(e)))
|
||||
.toList()
|
||||
: const [],
|
||||
suggestedCurrentKm: _asInt(j["suggestedCurrentKm"]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// What POST /me/import created. Every count is of brand-new records — the
|
||||
/// import never merges with or overwrites anything already there.
|
||||
class ImportResult {
|
||||
final int cars;
|
||||
final int services;
|
||||
final int parts;
|
||||
const ImportResult({this.cars = 0, this.services = 0, this.parts = 0});
|
||||
|
||||
factory ImportResult.fromJson(Map<String, dynamic> j) => ImportResult(
|
||||
cars: _asInt(j["carsImported"]),
|
||||
services: _asInt(j["servicesImported"]),
|
||||
parts: _asInt(j["partsImported"]),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user