Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: Fix Cash Payments #38

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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