首页 > 解决方案 > Flutter/Dart 如何使用 Flutter 从 Woocommerce API 访问订单?

问题描述

我正在关注这个 Git:https ://github.com/samarthagarwal/woocommerce_dart 。我正在访问 Woocommerce,但我没有从中获取数据。这是我用来访问 Woocommerce 并尝试在 Flutter 程序中显示数据的部分代码。希望可以有人帮帮我!!!

WooCommerceAPI wooCommerceAPI = WooCommerceAPI(
        url: "http://website.com/",
        consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

 
    List<Technician> techies = [];
    // Get data using the "orders" endpoint
    var data = await wooCommerceAPI.getAsync("orders");
    var jsonData = json.decode(data.body);
    for (var u in jsonData) {
        Technician myTechy = Technician(u["id"].toString(), u["status"].toString(), u["first_name"], u["last_name"]);

        techies.add(myTechy);
      }
    return techies; 

这是课程

class Technician {
  final String id;
  final String status;
  final String first_name;
  final String last_name;
  // String status;
  //int rating;
  //String occupation;

  Technician(this.id, this.status, this.first_name, this.last_name);
}

标签: apiflutterdartwoocommercewoocommerce-rest-api

解决方案


您正在使用 woocommerce_api 库,这有点令人困惑,请尝试改用 woocommerce 库。
你可以在这里
找到它 这是我用来从网站上获取产品的代码:

WooCommerce wooCommerce = WooCommerce( baseUrl: 'http://website.com/', consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', );

Future getProducts() async { var products= await wooCommerce.getProductCategories( perPage: 30, ); return products; }


推荐阅读