Skip to content

Commit

Permalink
Merge pull request #38 from pvdthings/dev
Browse files Browse the repository at this point in the history
Release: Fix Cash Payments
  • Loading branch information
dillonfagan committed Jul 22, 2024
2 parents 47633a7 + 205dd9c commit 9e07ca5
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BorrowersRepository extends Notifier<Future<List<BorrowerModel>>> {
.toList();
}

Future<bool> recordCashPayment({
Future<bool> recordPayment({
required String borrowerId,
required double cash,
}) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ class BorrowerDetails extends ConsumerWidget {
},
),
const SizedBox(height: 32),
const IssuesCard(),
IssuesCard(
borrowerId: borrower.id,
issues: borrower.issues,
),
const SizedBox(height: 32),
const PaymentsCard(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ class BorrowerIssues extends ConsumerWidget {
context: context,
builder: (context) {
return DuesNotPaidDialog(
instructions: issue.instructions!,
imageUrl: issue.graphicUrl,
onConfirmPayment: (cash) {
ref
.read(borrowersRepositoryProvider.notifier)
.recordCashPayment(
borrowerId: borrowerId, cash: cash)
.then(onRecordCashPayment);
});
instructions: issue.instructions!,
imageUrl: issue.graphicUrl,
onConfirmPayment: (cash) async {
final result = await ref
.read(borrowersRepositoryProvider.notifier)
.recordPayment(
borrowerId: borrowerId, cash: cash);

onRecordCashPayment(result);
},
);
},
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:librarian_app/modules/borrowers/models/issue_model.dart';
import 'package:librarian_app/modules/borrowers/widgets/borrower_details/borrower_issues.dart';
import 'package:librarian_app/widgets/details_card/card_header.dart';
import 'package:librarian_app/widgets/details_card/details_card.dart';

import '../../providers/selected_borrower_provider.dart';

class IssuesCard extends ConsumerWidget {
const IssuesCard({super.key});
const IssuesCard({
super.key,
required this.borrowerId,
required this.issues,
});

final String borrowerId;
final List<Issue> issues;

@override
Widget build(BuildContext context, WidgetRef ref) {
final borrower = ref.watch(selectedBorrowerProvider)!;

return DetailsCard(
header: const CardHeader(title: 'Issues'),
showDivider: borrower.issues.isNotEmpty,
showDivider: issues.isNotEmpty,
body: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: BorrowerIssues(
borrowerId: borrower.id,
issues: borrower.issues,
borrowerId: borrowerId,
issues: issues,
onRecordCashPayment: (success) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'record_payment_dialog.dart';
class DuesNotPaidDialog extends StatefulWidget {
final String instructions;
final String? imageUrl;
final void Function(double cash) onConfirmPayment;
final Future<void> Function(double cash) onConfirmPayment;

const DuesNotPaidDialog({
super.key,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

class RecordPaymentDialog extends StatefulWidget {
final void Function(double cash) onConfirmPayment;
final Future<void> Function(double cash) onConfirmPayment;

const RecordPaymentDialog({
super.key,
Expand All @@ -26,9 +26,12 @@ class _RecordPaymentDialogState extends State<RecordPaymentDialog> {
'Are you sure you want to record a \$${_cashController.text} cash payment?',
style: Theme.of(context).textTheme.bodyLarge,
),
onConfirm: () {
widget.onConfirmPayment(double.parse(_cashController.text));
Navigator.pop(context, true);
onConfirm: () async {
await widget.onConfirmPayment(double.parse(_cashController.text));

Future.delayed(Duration.zero, () {
Navigator.pop(context, true);
});
},
onCancel: () => Navigator.pop(context, false),
);
Expand Down
2 changes: 1 addition & 1 deletion apps/librarian/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
version: 1.0.0+10
version: 1.0.0+11

environment:
sdk: '>=3.0.0'
Expand Down

0 comments on commit 9e07ca5

Please sign in to comment.