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>
333 lines
12 KiB
Dart
333 lines
12 KiB
Dart
import "package:flutter/material.dart";
|
|
|
|
import "../i18n.dart";
|
|
import "../main.dart";
|
|
import "../models.dart";
|
|
import "../theme.dart";
|
|
|
|
/// Every tab a car's page can show, in the order they appear when the car has no
|
|
/// arrangement of its own. Information sits second because the connected
|
|
/// service, when there is one, is what you came to look at.
|
|
///
|
|
/// Mirrors ALL_TAB_KEYS in the web CarDetail and arrangeableCarTabs in the API's
|
|
/// cars.go — the server rejects any key outside that set.
|
|
const List<String> kCarTabKeys = [
|
|
"provider",
|
|
"info",
|
|
"services",
|
|
"technical",
|
|
"maintenance",
|
|
"fuel",
|
|
"charging",
|
|
"documents",
|
|
"parts",
|
|
"reminders",
|
|
];
|
|
|
|
/// The tabs that can be switched off. "info" is deliberately absent: it is the
|
|
/// car itself, and a page with no tabs left would be a dead end. It can still be
|
|
/// moved, which is why the two lists are separate.
|
|
const List<String> kHideableCarTabKeys = [
|
|
"provider",
|
|
"services",
|
|
"technical",
|
|
"maintenance",
|
|
"fuel",
|
|
"charging",
|
|
"documents",
|
|
"parts",
|
|
"reminders",
|
|
];
|
|
|
|
/// The Information rows, in their default order. Keys mirror hideableCarFields
|
|
/// in the API's cars.go.
|
|
const List<String> kCarInfoFieldKeys = [
|
|
"oilSpec",
|
|
"transmissionOil",
|
|
"differentialOil",
|
|
"brakeFluid",
|
|
"coolant",
|
|
"odometer",
|
|
"serviceInterval",
|
|
"nextDue",
|
|
"registrationPlate",
|
|
"registrationCountry",
|
|
"vin",
|
|
"fuelType",
|
|
"buildDate",
|
|
"firstRegistration",
|
|
];
|
|
|
|
/// Applies a car's stored arrangement to a catalogue of keys.
|
|
///
|
|
/// The stored order may be partial and may name keys this release does not know:
|
|
/// anything unrecognised is dropped, and any key it leaves out follows the ones
|
|
/// it names. That is what puts a tab or row added in a later release at the end
|
|
/// of somebody's page rather than in the middle of it.
|
|
List<String> arrangeKeys(List<String> catalogue, List<String> order) {
|
|
final arranged = <String>[];
|
|
for (final key in order) {
|
|
if (catalogue.contains(key) && !arranged.contains(key)) arranged.add(key);
|
|
}
|
|
arranged.addAll(catalogue.where((k) => !arranged.contains(k)));
|
|
return arranged;
|
|
}
|
|
|
|
/// What this car's page shows: which tabs and Information rows are on, and the
|
|
/// order of each. Mirrors the web's view picker, except that the web rearranges
|
|
/// by dragging the tab bar and the rows themselves — a gesture the tab bar owns
|
|
/// on a touch screen — so both arrangements are made here instead, with a handle.
|
|
///
|
|
/// Edited as a draft and saved in one write rather than on every checkbox:
|
|
/// switching several off one at a time would make the page rearrange under the
|
|
/// finger between taps. Pops the updated [Car] when it saved.
|
|
class CarViewSheet extends StatefulWidget {
|
|
final Car car;
|
|
|
|
/// Whether this car could show a connected-service tab at all. Offering to
|
|
/// hide a tab nobody can see would just be confusing.
|
|
final bool showProvider;
|
|
|
|
/// The provider's display name ("MyToyota"), used for that tab's label.
|
|
final String providerLabel;
|
|
|
|
const CarViewSheet({
|
|
super.key,
|
|
required this.car,
|
|
required this.showProvider,
|
|
this.providerLabel = "",
|
|
});
|
|
|
|
@override
|
|
State<CarViewSheet> createState() => _CarViewSheetState();
|
|
}
|
|
|
|
class _CarViewSheetState extends State<CarViewSheet> {
|
|
late List<String> _tabOrder;
|
|
late List<String> _fieldOrder;
|
|
late Set<String> _visibleTabs;
|
|
late Set<String> _visibleFields;
|
|
bool _saving = false;
|
|
String? _error;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
final car = widget.car;
|
|
_tabOrder = arrangeKeys(kCarTabKeys, car.tabOrder);
|
|
_fieldOrder = arrangeKeys(kCarInfoFieldKeys, car.fieldOrder);
|
|
_visibleTabs = kHideableCarTabKeys.where((k) => !car.hiddenTabs.contains(k)).toSet();
|
|
_visibleFields = kCarInfoFieldKeys.where((k) => !car.hiddenFields.contains(k)).toSet();
|
|
}
|
|
|
|
/// Whether [key] is one of the rows on offer below: Information never is
|
|
/// (it cannot be switched off), and the connected service only when this car
|
|
/// could show one.
|
|
bool _isRow(String key) =>
|
|
key != "info" && (key != "provider" || widget.showProvider);
|
|
|
|
/// The tab rows on offer, in the car's arrangement.
|
|
List<String> get _tabRows => _tabOrder.where(_isRow).toList();
|
|
|
|
String _tabLabel(String key) => key == "provider" && widget.providerLabel.isNotEmpty
|
|
? widget.providerLabel
|
|
: t("car.tabs.$key");
|
|
|
|
/// Applies a drag over the rows to the full arrangement, which holds keys the
|
|
/// rows do not offer. The movable slots are refilled from the new row
|
|
/// sequence and everything else keeps the position it already had, so
|
|
/// rearranging the rows can never move Information — or a connected-service
|
|
/// tab this car cannot show — out from under the user.
|
|
void _moveTab(int oldIndex, int newIndex) {
|
|
final rows = _tabRows;
|
|
rows.insert(newIndex, rows.removeAt(oldIndex));
|
|
setState(() {
|
|
var next = 0;
|
|
_tabOrder = [
|
|
for (final key in _tabOrder) _isRow(key) ? rows[next++] : key,
|
|
];
|
|
});
|
|
}
|
|
|
|
void _moveField(int oldIndex, int newIndex) {
|
|
setState(() => _fieldOrder.insert(newIndex, _fieldOrder.removeAt(oldIndex)));
|
|
}
|
|
|
|
Future<void> _save() async {
|
|
setState(() {
|
|
_saving = true;
|
|
_error = null;
|
|
});
|
|
try {
|
|
final car = await apiClient.updateCarView(
|
|
widget.car.id,
|
|
hiddenTabs: kHideableCarTabKeys.where((k) => !_visibleTabs.contains(k)).toList(),
|
|
hiddenFields: kCarInfoFieldKeys.where((k) => !_visibleFields.contains(k)).toList(),
|
|
tabOrder: _tabOrder,
|
|
fieldOrder: _fieldOrder,
|
|
);
|
|
if (mounted) Navigator.pop(context, car);
|
|
} catch (e) {
|
|
if (mounted) setState(() => _error = e.toString());
|
|
} finally {
|
|
if (mounted) setState(() => _saving = false);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final inset = MediaQuery.of(context).viewInsets.bottom;
|
|
return Padding(
|
|
padding: EdgeInsets.only(bottom: inset),
|
|
child: DraggableScrollableSheet(
|
|
expand: false,
|
|
initialChildSize: 0.85,
|
|
maxChildSize: 0.95,
|
|
builder: (context, scrollController) => Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(t("car.viewPicker.title"),
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700)),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.close),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: ListView(
|
|
controller: scrollController,
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
|
children: [
|
|
Text(t("car.viewPicker.subtitle"),
|
|
style: TextStyle(fontSize: 12, color: DriverVault.muted(context))),
|
|
const SizedBox(height: 16),
|
|
_heading(context, t("car.viewPicker.tabsHeading")),
|
|
ReorderableListView(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
buildDefaultDragHandles: false,
|
|
onReorderItem: _moveTab,
|
|
children: [
|
|
for (var i = 0; i < _tabRows.length; i++)
|
|
_row(
|
|
context,
|
|
index: i,
|
|
key: _tabRows[i],
|
|
label: _tabLabel(_tabRows[i]),
|
|
on: _visibleTabs.contains(_tabRows[i]),
|
|
onChanged: (v) => setState(() => v
|
|
? _visibleTabs.add(_tabRows[i])
|
|
: _visibleTabs.remove(_tabRows[i])),
|
|
),
|
|
],
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 6),
|
|
child: Text(
|
|
"${t("car.viewPicker.alwaysOn", params: {"tab": t("car.tabs.info")})}"
|
|
" ${t("car.viewPicker.reorderHint")}",
|
|
style: TextStyle(fontSize: 11, color: DriverVault.muted(context)),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
_heading(context, t("car.viewPicker.fieldsHeading")),
|
|
ReorderableListView(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
buildDefaultDragHandles: false,
|
|
onReorderItem: _moveField,
|
|
children: [
|
|
for (var i = 0; i < _fieldOrder.length; i++)
|
|
_row(
|
|
context,
|
|
index: i,
|
|
key: _fieldOrder[i],
|
|
label: t("car.info.${_fieldOrder[i]}"),
|
|
on: _visibleFields.contains(_fieldOrder[i]),
|
|
onChanged: (v) => setState(() => v
|
|
? _visibleFields.add(_fieldOrder[i])
|
|
: _visibleFields.remove(_fieldOrder[i])),
|
|
),
|
|
],
|
|
),
|
|
if (_error != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 12),
|
|
child: Text(_error!, style: const TextStyle(color: DriverVault.danger)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SafeArea(
|
|
top: false,
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton(
|
|
onPressed: _saving ? null : () => Navigator.pop(context),
|
|
child: Text(t("common.cancel")),
|
|
),
|
|
const SizedBox(width: 8),
|
|
FilledButton(
|
|
onPressed: _saving ? null : _save,
|
|
child: Text(_saving ? t("common.saving") : t("common.save")),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _heading(BuildContext context, String text) => Padding(
|
|
padding: const EdgeInsets.only(bottom: 4),
|
|
child: Text(text.toUpperCase(),
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w700,
|
|
letterSpacing: 0.6,
|
|
color: DriverVault.muted(context))),
|
|
);
|
|
|
|
/// One switchable, draggable row. The handle is explicit rather than
|
|
/// long-press-anywhere: the row's own tap target is the checkbox, and a
|
|
/// long-press drag would fight it.
|
|
Widget _row(
|
|
BuildContext context, {
|
|
required int index,
|
|
required String key,
|
|
required String label,
|
|
required bool on,
|
|
required ValueChanged<bool> onChanged,
|
|
}) =>
|
|
Padding(
|
|
key: ValueKey(key),
|
|
padding: const EdgeInsets.symmetric(vertical: 2),
|
|
child: Row(
|
|
children: [
|
|
Checkbox(value: on, onChanged: (v) => onChanged(v ?? false)),
|
|
Expanded(child: Text(label, style: const TextStyle(fontSize: 14))),
|
|
ReorderableDragStartListener(
|
|
index: index,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: Icon(Icons.drag_handle, color: DriverVault.muted(context)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|