mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2025-11-09 13:09:03 +00:00
Added: expanse planner app
This commit is contained in:
71
expense_planner/lib/widgets/transaction_list.dart
Normal file
71
expense_planner/lib/widgets/transaction_list.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../models/transaction.dart';
|
||||
|
||||
class TransactionList extends StatelessWidget {
|
||||
final List<Transaction> transactions;
|
||||
final Function deleteTx;
|
||||
|
||||
TransactionList(this.transactions, this.deleteTx);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: 450,
|
||||
child: transactions.isEmpty
|
||||
? Column(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'No transactions added yet!',
|
||||
style: Theme.of(context).textTheme.title,
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Container(
|
||||
height: 200,
|
||||
child: Image.asset(
|
||||
'assets/images/waiting.png',
|
||||
fit: BoxFit.cover,
|
||||
)),
|
||||
],
|
||||
)
|
||||
: ListView.builder(
|
||||
itemBuilder: (ctx, index) {
|
||||
return Card(
|
||||
elevation: 5,
|
||||
margin: EdgeInsets.symmetric(
|
||||
vertical: 8,
|
||||
horizontal: 5,
|
||||
),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
radius: 30,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(6),
|
||||
child: FittedBox(
|
||||
child: Text('\$${transactions[index].amount}'),
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
transactions[index].title,
|
||||
style: Theme.of(context).textTheme.title,
|
||||
),
|
||||
subtitle: Text(
|
||||
DateFormat.yMMMd().format(transactions[index].date),
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
color: Theme.of(context).errorColor,
|
||||
onPressed: () => deleteTx(transactions[index].id),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: transactions.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user