diff --git a/recipients_app/lib/data/repositories/user_repository.dart b/recipients_app/lib/data/repositories/user_repository.dart index 2ed0839a3..7fe6bfb6f 100644 --- a/recipients_app/lib/data/repositories/user_repository.dart +++ b/recipients_app/lib/data/repositories/user_repository.dart @@ -36,14 +36,14 @@ class UserRepository { return null; } - final userSnapshot = matchingUsers.docs.first; + final userSnapshot = matchingUsers.docs.firstOrNull; // This doesnt work because user id from firebaseAuth is not related to user id from firestore // Needs to be discussed if changes should be made or not // final userSnapshot = // await firestore.collection("/recipients").doc(firebaseUser.uid).get(); - if (userSnapshot.exists) { + if (userSnapshot != null && userSnapshot.exists) { // TODO: decide if we should keep it in user object in the app at all final payments = await PaymentRepository(firestore: firestore) .fetchPayments(recipientId: userSnapshot.id); diff --git a/recipients_app/lib/l10n/app_en.arb b/recipients_app/lib/l10n/app_en.arb index 8a3a917f0..ccd8b1ec5 100644 --- a/recipients_app/lib/l10n/app_en.arb +++ b/recipients_app/lib/l10n/app_en.arb @@ -50,6 +50,7 @@ "pastPayments" : "Past Payments", "futurePayments" : "Future Payments", "paymentsSuspended" : "Suspended", + "paymentsEmptyList": "No payments.", "survey" : "Survey", "createAccountInfo":"By creating an account, you agree with our ", "privacyPolicy":"Privacy Policy", diff --git a/recipients_app/lib/l10n/app_kri.arb b/recipients_app/lib/l10n/app_kri.arb index 40ee6dbbf..ce4b359a2 100644 --- a/recipients_app/lib/l10n/app_kri.arb +++ b/recipients_app/lib/l10n/app_kri.arb @@ -51,6 +51,7 @@ "pastPayments": "Pemɛnt dɛm we dɛn dɔn mek", "futurePayments": "Pemɛnt dɛm we yu nɔ gɛt yet", "paymentsSuspended": "Dɛn ɔl am fɔs", + "paymentsEmptyList": "Nɔ pemɛnt.", "survey": "Sɔve", "createAccountInfo": "We yu mek di akawnt, yu dɔn gri wit wi ", "privacyPolicy": "Wi de kip sikrit", diff --git a/recipients_app/lib/view/pages/payments_page.dart b/recipients_app/lib/view/pages/payments_page.dart index 5a66effae..209119dae 100644 --- a/recipients_app/lib/view/pages/payments_page.dart +++ b/recipients_app/lib/view/pages/payments_page.dart @@ -115,16 +115,29 @@ class PaymentsPage extends StatelessWidget { ), ), const SizedBox(height: 16), - Expanded( - child: ListView.builder( - itemCount: paymentsUiState.payments.length, - itemBuilder: (context, index) { - return PaymentTile( - mappedPayment: paymentsUiState.payments[index], - ); - }, + if (paymentsUiState.payments.isEmpty) + Expanded( + child: Padding( + padding: AppSpacings.a8, + child: Center( + child: Text( + localizations.paymentsEmptyList, + textAlign: TextAlign.center, + ), + ), + ), + ) + else + Expanded( + child: ListView.builder( + itemCount: paymentsUiState.payments.length, + itemBuilder: (context, index) { + return PaymentTile( + mappedPayment: paymentsUiState.payments[index], + ); + }, + ), ), - ), ], ), ), @@ -141,7 +154,7 @@ class PaymentsPage extends StatelessWidget { total += (mappedPayment.payment.amount ?? 0) ~/ factor; } - return "${mappedPayments.first.payment.currency} $total"; + return "${mappedPayments.firstOrNull?.payment.currency ?? "SLE"} $total"; } String _calculateFuturePayments(List mappedPayments) { @@ -150,6 +163,6 @@ class PaymentsPage extends StatelessWidget { final futurePayments = (kProgramDurationMonths - mappedPayments.length) * kCurrentPaymentAmount; - return "${mappedPayments.first.payment.currency} ${futurePayments}"; + return "${mappedPayments.firstOrNull?.payment.currency ?? "SLE"} ${futurePayments}"; } }