restreindre + et recherche à certains écrans; rendre les comptes modifiables

This commit is contained in:
alexis 2026-07-12 00:05:01 +02:00
parent dd792b6252
commit 5b4f3f7ec2
2 changed files with 94 additions and 12 deletions

View file

@ -158,16 +158,18 @@ class _YnabAppState extends ConsumerState<YnabApp> {
tooltip: 'Fermer la recherche',
)
else ...[
IconButton(
icon: Icon(Icons.add, color: colorScheme.primary),
onPressed: _addTransaction,
tooltip: 'Ajouter une transaction',
),
IconButton(
icon: Icon(Icons.search, color: colorScheme.onSurfaceVariant),
onPressed: _toggleSearch,
tooltip: 'Rechercher',
),
if (selectedIndex == 0 || selectedIndex == 3)
IconButton(
icon: Icon(Icons.add, color: colorScheme.primary),
onPressed: _addTransaction,
tooltip: 'Ajouter une transaction',
),
if (selectedIndex == 2 || selectedIndex == 3)
IconButton(
icon: Icon(Icons.search, color: colorScheme.onSurfaceVariant),
onPressed: _toggleSearch,
tooltip: 'Rechercher',
),
],
],
),

View file

@ -1,3 +1,5 @@
import 'package:drift/drift.dart' show Value;
import '../data/db.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/db_provider.dart';
@ -23,7 +25,7 @@ class AccountsScreen extends ConsumerWidget {
}
}
class _AccountCard extends StatelessWidget {
class _AccountCard extends ConsumerWidget {
final Account account;
const _AccountCard({required this.account});
@ -47,7 +49,7 @@ class _AccountCard extends StatelessWidget {
}
@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
return Card(
margin: const EdgeInsets.only(bottom: 8),
child: ListTile(
@ -64,7 +66,85 @@ class _AccountCard extends StatelessWidget {
color: account.balance >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
onTap: () => _editAccount(context, ref, account),
),
);
}
Future<void> _editAccount(BuildContext context, WidgetRef ref, Account account) async {
final db = ref.read(dbProvider);
final nameCtrl = TextEditingController(text: account.name);
final balanceCtrl = TextEditingController(text: account.balance.toStringAsFixed(2));
String type = account.type;
await showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Modifier le compte'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: nameCtrl,
decoration: const InputDecoration(labelText: 'Nom', hintText: 'Ex: Compte courant'),
),
const SizedBox(height: 12),
TextField(
controller: balanceCtrl,
decoration: const InputDecoration(labelText: 'Solde', hintText: '0,00'),
keyboardType: const TextInputType.numberWithOptions(decimal: true),
),
const SizedBox(height: 12),
DropdownButtonFormField<String>(
value: type,
decoration: const InputDecoration(labelText: 'Type'),
items: const [
DropdownMenuItem(value: 'checking', child: Text('Compte courant')),
DropdownMenuItem(value: 'savings', child: Text('Épargne')),
DropdownMenuItem(value: 'credit', child: Text('Carte de crédit')),
DropdownMenuItem(value: 'cash', child: Text('Espèces')),
],
onChanged: (v) {
if (v != null) type = v;
},
),
],
),
),
actions: [
TextButton(
onPressed: () async {
await (db.delete(db.accounts)..where((t) => t.id.equals(account.id))).go();
if (ctx.mounted) Navigator.pop(ctx);
},
style: TextButton.styleFrom(foregroundColor: Theme.of(context).colorScheme.error),
child: const Text('Supprimer'),
),
const Spacer(),
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Annuler'),
),
FilledButton(
onPressed: () async {
final name = nameCtrl.text.trim();
final balanceStr = balanceCtrl.text.trim().replaceAll(',', '.');
final balance = double.tryParse(balanceStr);
if (name.isEmpty || balance == null) return;
await (db.update(db.accounts)..where((t) => t.id.equals(account.id))).write(AccountsCompanion(
name: Value(name),
type: Value(type),
balance: Value(balance),
));
if (ctx.mounted) Navigator.pop(ctx);
},
child: const Text('Enregistrer'),
),
],
),
);
nameCtrl.dispose();
balanceCtrl.dispose();
}
}