restreindre + et recherche à certains écrans; rendre les comptes modifiables
This commit is contained in:
parent
dd792b6252
commit
5b4f3f7ec2
|
|
@ -158,11 +158,13 @@ class _YnabAppState extends ConsumerState<YnabApp> {
|
||||||
tooltip: 'Fermer la recherche',
|
tooltip: 'Fermer la recherche',
|
||||||
)
|
)
|
||||||
else ...[
|
else ...[
|
||||||
|
if (selectedIndex == 0 || selectedIndex == 3)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.add, color: colorScheme.primary),
|
icon: Icon(Icons.add, color: colorScheme.primary),
|
||||||
onPressed: _addTransaction,
|
onPressed: _addTransaction,
|
||||||
tooltip: 'Ajouter une transaction',
|
tooltip: 'Ajouter une transaction',
|
||||||
),
|
),
|
||||||
|
if (selectedIndex == 2 || selectedIndex == 3)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.search, color: colorScheme.onSurfaceVariant),
|
icon: Icon(Icons.search, color: colorScheme.onSurfaceVariant),
|
||||||
onPressed: _toggleSearch,
|
onPressed: _toggleSearch,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:drift/drift.dart' show Value;
|
||||||
|
import '../data/db.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import '../providers/db_provider.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;
|
final Account account;
|
||||||
const _AccountCard({required this.account});
|
const _AccountCard({required this.account});
|
||||||
|
|
||||||
|
|
@ -47,7 +49,7 @@ class _AccountCard extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return Card(
|
return Card(
|
||||||
margin: const EdgeInsets.only(bottom: 8),
|
margin: const EdgeInsets.only(bottom: 8),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
|
|
@ -64,7 +66,85 @@ class _AccountCard extends StatelessWidget {
|
||||||
color: account.balance >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue