8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

从 firestore 检索数据后,数据未在 Flutter 应用程序上相应显示

Luke Krell 2月前

23 0

当从 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),
              ),
            ),
          ),
        ],
      ),
    );
  }),

保存之前和检索之后的数据应该显示相同。

帖子版权声明 1、本帖标题:从 firestore 检索数据后,数据未在 Flutter 应用程序上相应显示
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由Luke Krell在本站《firebase》版块原创发布, 转载请注明出处!
最新回复 (0)
返回
作者最近主题: