Flutter & Woocommerce 其余 api 用于订单备注

Flutter & Woocommerce rest api for order notes

你好,我一直很难解决以下问题我只想显示来自 woocommmerce 的值为“customer_note”的订单备注:true,请参阅 Json 向下请求

{
"id": 281,
"author": "system",
"date_created": "2017-03-21T16:46:41",
"date_created_gmt": "2017-03-21T19:46:41",
"note": "Order ok!!!",
"customer_note": false,
}

这就是我的 flutter 代码中保存订单备注数据的方式。

  @override


Future<List<OrderNote>> getOrderNote(
      {String? userId, String? orderId}) async {
    try {
      var response = await wcApi
          .getAsync('orders/$orderId/notes?customer=$userId&per_page=20');
      var list = <OrderNote>[];
      if (response is Map && isNotBlank(response['message'])) {
        throw Exception(response['message']);
      } else {
        for (var item in response) {
//          if (item.type == 'customer') {
          /// it is possible to update to `any` note
          /// ref: https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-order-notes
          list.add(OrderNote.fromJson(item));
//          }
        }
        return list;
      }
    } catch (e) {

      rethrow;
    }
  }

如何在for循环中添加一个条件来检查项目中customer_note的值来决定是否将其添加到列表中,如下所示:

for (var item in response) {
    if (item['customer_note'])
    {
        // customer_note == true
        list.add(OrderNote.fromJson(item));
    }
}

我还用以下过滤包含特定单词的订单注释

if (item['note'].contains('État'))
        {
        list.add(OrderNote.fromJson(item));
      }