api - 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);
}
解决方案
您正在使用 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; }
推荐阅读
- php - 如何从 CodeIgniter 3 连接到 SQL Server 数据库?
- ios - 在 Swift 中的过渡更改后移动事物
- mongodb - mongodb设置对象,其中键值动态变化
- view - CouchDB 多级视图地图功能?
- cakephp - cakephp 3.7 如何设置邮件布局和模板
- ios - iOS Application_Home/Library/Caches 目录经常被清除
- angular - 如果用户已经登录,则显示/隐藏我的菜单
- java - 如何通过多个id找到一些数据?
- docker - Windows 10 Linux 子系统中的 Dockerfile 在当前目录中找不到文件
- django - 每个用户的合同的首次记录开始日期、最后记录结束日期以及如何应用过滤器