91 lines
No EOL
2.4 KiB
Dart
91 lines
No EOL
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../core/utils/shared_provider.dart';
|
|
import 'splitter_provider.dart';
|
|
|
|
class SplitterModule extends ConsumerWidget {
|
|
const SplitterModule({super.key});
|
|
|
|
@override
|
|
class SplitterModule extends ConsumerWidget {
|
|
const SplitterModule({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final currentVal = ref.watch(sharedValueProvider); // Il totale dalla calcolatrice
|
|
final splitter = ref.watch(splitterProvider);
|
|
final logic = ref.read(splitterProvider.notifier);
|
|
final nameCtrl = TextEditingController();
|
|
|
|
return Column(
|
|
children: [
|
|
// AREA DI INSERIMENTO RAPIDO
|
|
Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
children: [
|
|
TextField(
|
|
controller: nameCtrl,
|
|
decoration: InputDecoration(
|
|
labelText: "Nome Amico",
|
|
suffixIcon: IconButton(
|
|
icon: const Icon(Icons.add_circle, size: 35, color: Colors.deepPurple),
|
|
onPressed: () {
|
|
if (nameCtrl.text.isNotEmpty) {
|
|
// AGGIUNGE L'AMICO CON LA CIFRA ATTUALE DELLA CALCOLATRICE
|
|
logic.addFriend(nameCtrl.text, currentVal);
|
|
nameCtrl.clear();
|
|
}
|
|
},
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
"Verrà aggiunto con la quota di: ${currentVal.toStringAsFixed(2)} €",
|
|
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// LISTA PARTECIPANTI
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: splitter.friends.length,
|
|
itemBuilder: (context, index) {
|
|
final friend = splitter.friends[index];
|
|
return Card(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
|
child: ListTile(
|
|
leading: const Icon(Icons.person),
|
|
title: Text(friend.name),
|
|
trailing: Text("${friend.spent.toStringAsFixed(2)} €",
|
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
|
|
// RISULTATO OTTIMIZZATO (Chi deve dare a chi)
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: Colors.deepPurple.withOpacity(0.1),
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(30)),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
const Text("RIEPILOGO PAREGGIO", style: TextStyle(fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 10),
|
|
...logic.calculateSettlements().map((msg) => Text(msg, textAlign: TextAlign.center)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
} |