如何解决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 库。
你可以找到它here
这是我用来从网站获取产品的代码:
export default function App({ num }) {
const [arr,setValue] = useState(Array(num).fill(""));
console.log(arr);
function onInputChange(index,event) {
console.log(event.target.value);
setValue((os) => {
const temp = [...os];
temp[index] = event.target.value;
return temp;
});
}
return (
<div className="App">
{arr.map((n,i) => {
return (
<div key={i}>
<input onChange={(e) => onInputChange(i,e)} value={n} />
</div>
);
})}
</div>
);
}
WooCommerce wooCommerce = WooCommerce( baseUrl: 'http://website.com/',consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。