当从 Firestore 检索到“selectedNumbers”、“fRAmount”、“sRAmount”时,它不会相应地显示。我附上了屏幕截图,显示了它在保存到 Firestore 之前和检索之后的显示情况。我也
从 Firestore 检索“selectedNumbers”、“fRAmount”、“sRAmount”时,不会相应显示。我附上了屏幕截图,显示了在保存到 Firestore 之前和检索之后的显示情况。我还附上了 Firestore 的屏幕截图。
p2
p3
p4
从 Paymenscreen 类保存到 Firestore -
Future<void> createOrderAndInitiatePayment(BuildContext context) async {
List<String?> cleanedFRAmounts = fRAmounts
.where((amount) => amount != null && amount.isNotEmpty)
.toList();
List<String?> cleanedSRAmounts = sRAmounts
.where((amount) => amount != null && amount.isNotEmpty)
.toList();
//order data
final orderData = {
"selected_numbers":
selectedNumbers.map((number) => number.toString()).toList(),
"f_r_amounts": cleanedFRAmounts,
"s_r_amounts": cleanedSRAmounts,
};
// Save to Firestore
try {
await FirebaseFirestore.instance
.collection('orders')
.doc(orderId)
.set(orderData);
print('Order saved to Firestore');
} catch (e) {
print('Error saving order to Firestore: $e');
}
//selectedNumbers, fRAmount, sRAmount saved UI on paymentScreen class
...selectedNumbers.map((number) {
String? frAmount = number < fRAmounts.length
? fRAmounts[number]
: null;
String? srAmount = number < sRAmounts.length
? sRAmounts[number]
: null;
return ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: Text(
number.toString(), // Convert int to String
style: const TextStyle(
fontSize: 18.0,
),
),
),
),
const SizedBox(width: 16.0),
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: Text(
(frAmount != null) ? '₹$frAmount' : '×',
style: const TextStyle(
fontSize: 18.0,
),
),
),
),
const SizedBox(width: 16.0),
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: Text(
(srAmount != null) ? '₹$srAmount' : '×',
style: const TextStyle(
fontSize: 18.0,
),
),
),
),
],
),
);
}),
在 paymentResponseHandler 上检索后 -
final selectedNumbers = List<int>.from(
(data['selected_numbers'] as List)
.map((e) => int.parse(e.toString())));
final fRAmounts = List<String?>.from(data['f_r_amounts']);
final sRAmounts = List<String?>.from(data['s_r_amounts']);
// UI of selectedNumebers, framount, sramount on paymentresponsehandler
...selectedNumbers.map((number) {
int index = selectedNumbers.indexOf(number);
String? frAmount = index < fRAmounts.length
? fRAmounts[index]
: null;
String? srAmount = index < sRAmounts.length
? sRAmounts[index]
: null;
return ListTile(
title: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: Text(
number.toString(),
style: const TextStyle(fontSize: 18.0),
),
),
),
const SizedBox(width: 16.0),
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: Text(
(frAmount != null) ? '₹$frAmount' : '×',
style: const TextStyle(fontSize: 18.0),
),
),
),
const SizedBox(width: 16.0),
Expanded(
flex: 1,
child: Container(
alignment: Alignment.center,
child: Text(
(srAmount != null) ? '₹$srAmount' : '×',
style: const TextStyle(fontSize: 18.0),
),
),
),
],
),
);
}),
保存之前和检索之后的数据应该显示相同。