Skip to content

Commit 5728978

Browse files
authored
chore(recipients-app): Fix grey empty payments (#628)
* Fix problem with null pointer in payments list * Add empty payments list string
1 parent 8f64f06 commit 5728978

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

recipients_app/lib/data/repositories/user_repository.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class UserRepository {
3636
return null;
3737
}
3838

39-
final userSnapshot = matchingUsers.docs.first;
39+
final userSnapshot = matchingUsers.docs.firstOrNull;
4040

4141
// This doesnt work because user id from firebaseAuth is not related to user id from firestore
4242
// Needs to be discussed if changes should be made or not
4343
// final userSnapshot =
4444
// await firestore.collection("/recipients").doc(firebaseUser.uid).get();
4545

46-
if (userSnapshot.exists) {
46+
if (userSnapshot != null && userSnapshot.exists) {
4747
// TODO: decide if we should keep it in user object in the app at all
4848
final payments = await PaymentRepository(firestore: firestore)
4949
.fetchPayments(recipientId: userSnapshot.id);

recipients_app/lib/l10n/app_en.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"pastPayments" : "Past Payments",
5151
"futurePayments" : "Future Payments",
5252
"paymentsSuspended" : "Suspended",
53+
"paymentsEmptyList": "No payments.",
5354
"survey" : "Survey",
5455
"createAccountInfo":"By creating an account, you agree with our ",
5556
"privacyPolicy":"Privacy Policy",

recipients_app/lib/l10n/app_kri.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"pastPayments": "Pemɛnt dɛm we dɛn dɔn mek",
5252
"futurePayments": "Pemɛnt dɛm we yu nɔ gɛt yet",
5353
"paymentsSuspended": "Dɛn ɔl am fɔs",
54+
"paymentsEmptyList": "Nɔ pemɛnt.",
5455
"survey": "Sɔve",
5556
"createAccountInfo": "We yu mek di akawnt, yu dɔn gri wit wi ",
5657
"privacyPolicy": "Wi de kip sikrit",

recipients_app/lib/view/pages/payments_page.dart

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,29 @@ class PaymentsPage extends StatelessWidget {
115115
),
116116
),
117117
const SizedBox(height: 16),
118-
Expanded(
119-
child: ListView.builder(
120-
itemCount: paymentsUiState.payments.length,
121-
itemBuilder: (context, index) {
122-
return PaymentTile(
123-
mappedPayment: paymentsUiState.payments[index],
124-
);
125-
},
118+
if (paymentsUiState.payments.isEmpty)
119+
Expanded(
120+
child: Padding(
121+
padding: AppSpacings.a8,
122+
child: Center(
123+
child: Text(
124+
localizations.paymentsEmptyList,
125+
textAlign: TextAlign.center,
126+
),
127+
),
128+
),
129+
)
130+
else
131+
Expanded(
132+
child: ListView.builder(
133+
itemCount: paymentsUiState.payments.length,
134+
itemBuilder: (context, index) {
135+
return PaymentTile(
136+
mappedPayment: paymentsUiState.payments[index],
137+
);
138+
},
139+
),
126140
),
127-
),
128141
],
129142
),
130143
),
@@ -141,7 +154,7 @@ class PaymentsPage extends StatelessWidget {
141154
total += (mappedPayment.payment.amount ?? 0) ~/ factor;
142155
}
143156

144-
return "${mappedPayments.first.payment.currency} $total";
157+
return "${mappedPayments.firstOrNull?.payment.currency ?? "SLE"} $total";
145158
}
146159

147160
String _calculateFuturePayments(List<MappedPayment> mappedPayments) {
@@ -150,6 +163,6 @@ class PaymentsPage extends StatelessWidget {
150163
final futurePayments = (kProgramDurationMonths - mappedPayments.length) *
151164
kCurrentPaymentAmount;
152165

153-
return "${mappedPayments.first.payment.currency} ${futurePayments}";
166+
return "${mappedPayments.firstOrNull?.payment.currency ?? "SLE"} ${futurePayments}";
154167
}
155168
}

0 commit comments

Comments
 (0)