mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:07:04 +01:00
flutter analyze --fatal-infos exited 1 at6713ef3with four unnecessary_unawaited issues in lib/ui/home_screen.dart: Flutter now annotates Navigator.push with @awaitNotRequired, which makes the unawaited() wrappers redundant. Removed all four wrappers and the dart:async import they were the only user of. dart format --set-exit-if-changed was separately red on three test files left unformatted bya68313f. One trailing blank line each. Both are steps in .github/workflows/billsplit-ci.yml, so billsplit CI was failing on main for reasons unrelated to any current work. Fixing them first means the platform-directory deletion that follows can be verified green-to-green. flutter test: 60 passing before and after - the unchanged count is what proves the unawaited() removals did not shift navigation timing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
211 lines
7.3 KiB
Dart
211 lines
7.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:billsplit/domain/eparagon_parser.dart';
|
|
import 'package:billsplit/domain/models.dart';
|
|
import 'package:billsplit/state/app_state.dart';
|
|
import 'package:billsplit/ui/people_screen.dart';
|
|
import 'package:billsplit/ui/receipt_screen.dart';
|
|
import 'package:design_system/design_system.dart';
|
|
import 'package:file_selector/file_selector.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
/// Receipt list plus entry points for import / manual creation.
|
|
class HomeScreen extends StatelessWidget {
|
|
/// Creates the home screen.
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = context.watch<AppState>();
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('BillSplit'),
|
|
actions: [
|
|
IconButton(
|
|
tooltip: 'People & groups',
|
|
icon: const Icon(Icons.group),
|
|
onPressed: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute<void>(builder: (_) => const PeopleScreen()),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: !state.loaded
|
|
? const Center(child: CircularProgressIndicator())
|
|
: state.receipts.isEmpty
|
|
? const _EmptyHint()
|
|
: ListView.builder(
|
|
itemCount: state.receipts.length,
|
|
itemBuilder: (context, i) {
|
|
final r = state.receipts[i];
|
|
return Dismissible(
|
|
key: ValueKey(r.id),
|
|
direction: DismissDirection.endToStart,
|
|
// The delete affordance revealed by swiping. The fill
|
|
// and the icon on top of it must move together, hence
|
|
// error/onError rather than two independent colours.
|
|
background: Container(
|
|
color: Theme.of(context).colorScheme.error,
|
|
alignment: Alignment.centerRight,
|
|
padding: const EdgeInsets.only(right: AppSpacing.md),
|
|
child: Icon(
|
|
Icons.delete,
|
|
color: Theme.of(context).colorScheme.onError,
|
|
),
|
|
),
|
|
confirmDismiss: (_) => _confirmDelete(context, r),
|
|
onDismissed: (_) => state.removeReceipt(r),
|
|
child: ListTile(
|
|
title: Text(r.title),
|
|
subtitle: Text(
|
|
'${r.items.length} items · '
|
|
'${r.participantIds.length} people',
|
|
),
|
|
trailing: Text(
|
|
formatPln(r.itemsTotalGr),
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => ReceiptScreen(receiptId: r.id),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
floatingActionButton: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
FloatingActionButton.extended(
|
|
heroTag: 'import',
|
|
icon: const Icon(Icons.file_download),
|
|
label: const Text('Import e-paragon'),
|
|
onPressed: () => _import(context),
|
|
),
|
|
const SizedBox(height: 12),
|
|
FloatingActionButton.extended(
|
|
heroTag: 'new',
|
|
icon: const Icon(Icons.add),
|
|
label: const Text('New receipt'),
|
|
onPressed: () => _createManual(context),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<bool> _confirmDelete(BuildContext context, Receipt r) async {
|
|
return await showDialog<bool>(
|
|
context: context,
|
|
builder: (c) => AlertDialog(
|
|
title: const Text('Delete receipt?'),
|
|
content: Text('"${r.title}" will be removed permanently.'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(c, false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.pop(c, true),
|
|
child: const Text('Delete'),
|
|
),
|
|
],
|
|
),
|
|
) ??
|
|
false;
|
|
}
|
|
|
|
Future<void> _import(BuildContext context) async {
|
|
final state = context.read<AppState>();
|
|
final messenger = ScaffoldMessenger.of(context);
|
|
final nav = Navigator.of(context);
|
|
const jsonGroup = XTypeGroup(
|
|
label: 'e-paragon',
|
|
extensions: ['json'],
|
|
// Android matches on MIME rather than extension; without this the
|
|
// picker greys out every file.
|
|
mimeTypes: ['application/json'],
|
|
uniformTypeIdentifiers: ['public.json'],
|
|
);
|
|
final picked = await openFile(acceptedTypeGroups: [jsonGroup]);
|
|
if (picked == null) return;
|
|
final data = await picked.readAsBytes();
|
|
try {
|
|
final result = parseEParagonDetailed(utf8.decode(data));
|
|
state.addReceipt(result.receipt);
|
|
for (final w in result.warnings) {
|
|
messenger.showSnackBar(SnackBar(content: Text(w)));
|
|
}
|
|
nav.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => ReceiptScreen(receiptId: result.receipt.id),
|
|
),
|
|
);
|
|
} on EParagonParseException catch (e) {
|
|
messenger.showSnackBar(SnackBar(content: Text(e.message)));
|
|
} on Exception catch (e) {
|
|
messenger.showSnackBar(SnackBar(content: Text('Import failed: $e')));
|
|
}
|
|
}
|
|
|
|
Future<void> _createManual(BuildContext context) async {
|
|
final state = context.read<AppState>();
|
|
final nav = Navigator.of(context);
|
|
final controller = TextEditingController();
|
|
final title = await showDialog<String>(
|
|
context: context,
|
|
builder: (c) => AlertDialog(
|
|
title: const Text('New receipt'),
|
|
content: TextField(
|
|
controller: controller,
|
|
autofocus: true,
|
|
decoration: const InputDecoration(labelText: 'Title'),
|
|
onSubmitted: (v) => Navigator.pop(c, v),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(c),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.pop(c, controller.text),
|
|
child: const Text('Create'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (title == null || title.trim().isEmpty) return;
|
|
final r = Receipt(id: Ids.next(), title: title.trim());
|
|
state.addReceipt(r);
|
|
nav.push(
|
|
MaterialPageRoute<void>(
|
|
builder: (_) => ReceiptScreen(receiptId: r.id),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _EmptyHint extends StatelessWidget {
|
|
const _EmptyHint();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(32),
|
|
child: Text(
|
|
'No receipts yet.\n\nAdd people first (top right), then import a '
|
|
'Biedronka e-paragon JSON or create a receipt manually.',
|
|
textAlign: TextAlign.center,
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|