mirrored_repositories/Personal-Expenses-Manager/lib
import 'package:flutter/material.dart';
import '../models/transaction.dart';
import 'package:intl/intl.dart';

class TransactionList extends StatelessWidget {
  final List<Transaction> transactions;
  final Function deleteTx;
  TransactionList(this.transactions,this.deleteTx);

  @override
  Widget build(BuildContext context) {
    return transactions.isEmpty
            ? LayoutBuilder(builder:(ctx,constraints){
            return Column(children: <Widget>[
                Text(
                  'No Transaction added yet!',
                  style: Theme.of(context).textTheme.title,
                ),
                SizedBox(
                  height: 10,
                ),
                Container(
                    height: constraints.maxHeight*0.6,
                    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,
              );
            
  }
}
