import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:get_it/get_it.dart'; import 'package:okane/database/database.dart'; import 'package:okane/ui/pages/loans/add_loan.dart'; import 'package:okane/ui/state/core.dart'; import 'package:okane/ui/utils.dart'; import 'package:okane/ui/widgets/image_wrapper.dart'; class LoanListPage extends StatelessWidget { const LoanListPage({super.key}); @override Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { return Stack( children: [ ListView.builder( itemCount: state.loans.length, itemBuilder: (context, index) { final item = state.loans[index]; final beneficiary = item.beneficiary.value!; return ListTile( leading: ImageWrapper( title: beneficiary.name, path: beneficiary.imagePath, ), onTap: () { GetIt.I.get().setActiveLoan(item); }, trailing: IconButton( onPressed: () async { final result = await confirm( context, "Delete Loan", "Are you sure you want to delete the loan?", ); if (!result) { return; } await deleteLoan(item); }, icon: Icon(Icons.delete, color: Colors.red), ), title: Text(beneficiary.name), ); }, ), Positioned( right: 16, bottom: 16, child: FloatingActionButton( child: Icon(Icons.add), onPressed: () { showDialogOrModal( context: context, builder: (_) => AddLoanPopup( onDone: () { Navigator.of(context).pop(); }, ), ); }, ), ), ], ); }, ); } }