You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.4 KiB
Dart
89 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
import '../models/transaction.dart';
|
|
|
|
class TransactionList extends StatelessWidget {
|
|
final List<Transaction> transactions;
|
|
final Function removeTransactionCallback;
|
|
|
|
const TransactionList(this.transactions, this.removeTransactionCallback);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return transactions.isEmpty
|
|
? LayoutBuilder(
|
|
builder: (BuildContext ctx, BoxConstraints constraints) {
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Text(
|
|
'There is no transaction yet!',
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
SizedBox(
|
|
height: constraints.maxHeight * 0.8,
|
|
child: Image.asset(
|
|
'assets/images/waiting.png',
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
)
|
|
: ListView.builder(
|
|
itemBuilder: (BuildContext buildContext, int index) {
|
|
return Card(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10)),
|
|
color: Colors.white,
|
|
margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
|
child: ListTile(
|
|
leading: CircleAvatar(
|
|
radius: 30,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(6),
|
|
child: FittedBox(
|
|
child: Text(
|
|
'${transactions[index].amount} €',
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
)),
|
|
),
|
|
),
|
|
title: Text(
|
|
transactions[index].title,
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
subtitle: Text(
|
|
DateFormat.yMMMMd().format(transactions[index].date)),
|
|
trailing: MediaQuery.of(context).size.width > 400
|
|
? ElevatedButton.icon(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.white,
|
|
foregroundColor: Colors.red,
|
|
elevation: 0,
|
|
),
|
|
onPressed: () {
|
|
removeTransactionCallback(transactions[index].id);
|
|
},
|
|
icon: const Icon(Icons.delete),
|
|
label: const Text(
|
|
'Supprimer',
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
)
|
|
: IconButton(
|
|
icon: Icon(Icons.delete),
|
|
color: Theme.of(context).colorScheme.error,
|
|
onPressed: () {
|
|
removeTransactionCallback(transactions[index].id);
|
|
},
|
|
)),
|
|
);
|
|
},
|
|
itemCount: transactions.length,
|
|
);
|
|
}
|
|
}
|