mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-11-10 19:27:05 +01:00
Last of the four drifted apps. The theme was ColorScheme.fromSeed(teal) plus fifteen ad hoc colour literals that mostly bypassed it -- not one widget outside main.dart read colorScheme at all, so the seed barely affected what you saw. It now uses design_system-v0.1.0's buildLightTheme(), and the literals that have a real theme role read it off the scheme. Light, not dark, deliberately: the receipt screens carry black-on-white helper text, so inverting brightness would make it unreadable. The Colors.black54 sites are exactly those, now onSurfaceVariant. The error family maps cleanly -- Colors.red to error, red.shade50 to errorContainer with onErrorContainer text on it, and the swipe-to-delete background+icon to error/onError so the fill and the glyph drawn on it cannot drift apart. The four category dots (deepOrange/amber/blueGrey/teal) stay literals, with a comment saying why: they encode which category an item is, not a theme role, and a single-accent system has no four distinct hues to lend them. Mapping them onto primary/secondary/tertiary would make the categories stop being distinguishable, which is their only job. They are tracked in nielsen-audit.md as needing a categorical ramp. Note this decouples the default dot from the old seed -- both were Colors.teal, so they used to match by coincidence rather than by design. Verified: 60/60 tests, 100% line coverage across 11 lib files, analyze clean apart from four pre-existing unnecessary_unawaited infos. A temporary assertion pumped the real app and read primary=ffb8862e and surface=fff6f4f3 off a live Scaffold, confirming the palette changed rather than merely compiling. Colour literals: 15 -> 4. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XS1m7b1piBtAL22USLW6jL
138 lines
4.7 KiB
Dart
138 lines
4.7 KiB
Dart
import 'package:billsplit/domain/models.dart';
|
|
import 'package:billsplit/state/app_state.dart';
|
|
import 'package:design_system/design_system.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Add ([item] == null) or edit an item. The user types amounts in złoty
|
|
/// ("12,34" or "12.34"); they are stored as int grosze.
|
|
Future<void> showItemEditDialog(
|
|
BuildContext context,
|
|
AppState state,
|
|
Receipt receipt,
|
|
Item? item,
|
|
) async {
|
|
final name = TextEditingController(text: item?.name ?? '');
|
|
final total = TextEditingController(
|
|
text: item == null ? '' : _zl(item.totalGr),
|
|
);
|
|
final qty = TextEditingController(text: (item?.qty ?? 1).toString());
|
|
var category = item?.category ?? Categories.general;
|
|
final categories = <String>{
|
|
Categories.general,
|
|
Categories.alcohol,
|
|
Categories.mixer,
|
|
Categories.deposit,
|
|
...receipt.items.map((i) => i.category),
|
|
}.toList();
|
|
|
|
await showDialog<void>(
|
|
context: context,
|
|
builder: (c) => StatefulBuilder(
|
|
builder: (c, setState) => AlertDialog(
|
|
title: Text(item == null ? 'Add item' : 'Edit item'),
|
|
content: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
controller: name,
|
|
autofocus: item == null,
|
|
decoration: const InputDecoration(labelText: 'Name'),
|
|
),
|
|
TextField(
|
|
controller: total,
|
|
keyboardType:
|
|
const TextInputType.numberWithOptions(decimal: true),
|
|
decoration: const InputDecoration(
|
|
labelText: 'Total (zł)',
|
|
hintText: 'e.g. 12,34',
|
|
),
|
|
),
|
|
TextField(
|
|
controller: qty,
|
|
keyboardType:
|
|
const TextInputType.numberWithOptions(decimal: true),
|
|
decoration: const InputDecoration(labelText: 'Quantity'),
|
|
),
|
|
const SizedBox(height: 8),
|
|
DropdownButtonFormField<String>(
|
|
initialValue: category,
|
|
decoration: const InputDecoration(labelText: 'Category'),
|
|
items: [
|
|
for (final cat in categories)
|
|
DropdownMenuItem(value: cat, child: Text(cat)),
|
|
],
|
|
onChanged: (v) =>
|
|
setState(() => category = v ?? Categories.general),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'Alcohol items default to drinkers only; everything else to '
|
|
'everyone. Fine-tune by tapping the item afterwards.',
|
|
style: TextStyle(
|
|
fontSize: AppTextSize.caption,
|
|
color: Theme.of(c).colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
actions: [
|
|
if (item != null)
|
|
TextButton(
|
|
onPressed: () {
|
|
state.mutate(() => receipt.items.remove(item));
|
|
Navigator.pop(c);
|
|
},
|
|
child: Text(
|
|
'Delete',
|
|
style: TextStyle(color: Theme.of(c).colorScheme.error),
|
|
),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(c),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () {
|
|
final gr = _parseZl(total.text);
|
|
if (name.text.trim().isEmpty || gr == null) return;
|
|
state.mutate(() {
|
|
if (item == null) {
|
|
final it = Item(
|
|
id: Ids.next(),
|
|
name: name.text.trim(),
|
|
totalGr: gr,
|
|
qty: double.tryParse(qty.text.replaceAll(',', '.')) ?? 1,
|
|
category: category,
|
|
assignment: category == Categories.alcohol
|
|
? Assignment(mode: AssignMode.drinkers)
|
|
: Assignment(),
|
|
);
|
|
receipt.items.add(it);
|
|
} else {
|
|
item
|
|
..name = name.text.trim()
|
|
..totalGr = gr
|
|
..qty = double.tryParse(qty.text.replaceAll(',', '.')) ?? 1
|
|
..category = category;
|
|
}
|
|
});
|
|
Navigator.pop(c);
|
|
},
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _zl(int gr) => (gr / 100).toStringAsFixed(2);
|
|
|
|
int? _parseZl(String s) {
|
|
final v = double.tryParse(s.replaceAll(',', '.').replaceAll(' ', ''));
|
|
if (v == null) return null;
|
|
return (v * 100).round();
|
|
}
|