Skip to content

Commit 2b27d92

Browse files
committed
update README
1 parent 577a682 commit 2b27d92

File tree

1 file changed

+15
-92
lines changed

1 file changed

+15
-92
lines changed

README.md

Lines changed: 15 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -4,102 +4,25 @@ A dart package to interact with the WooCommerce API. It uses OAuth1.0a behind th
44

55
![Example code and preview](Screenshot.png)
66

7-
## Complete Usage Example
8-
```dart
9-
import 'dart:async';
10-
11-
import 'package:flutter/material.dart';
12-
import 'package:woocommerce_api/woocommerce_api.dart';
13-
14-
void main() => runApp(new MyApp());
15-
16-
class MyApp extends StatelessWidget {
17-
@override
18-
Widget build(BuildContext context) {
19-
return new MaterialApp(
20-
title: 'Flutter Demo',
21-
theme: new ThemeData(
22-
primarySwatch: Colors.blue,
23-
),
24-
home: new MyHomePage(title: 'WooCommerce API Demo'),
25-
);
26-
}
27-
}
28-
29-
class MyHomePage extends StatefulWidget {
30-
MyHomePage({Key key, this.title}) : super(key: key);
31-
32-
final String title;
33-
34-
@override
35-
_MyHomePageState createState() => new _MyHomePageState();
36-
}
37-
38-
class _MyHomePageState extends State<MyHomePage> {
39-
40-
List<Widget> products = [];
7+
## Examples
418

42-
Future getProducts() async {
43-
44-
/// Initialize the API
45-
WooCommerceAPI wc_api = new WooCommerceAPI(
46-
url: "https://www.yourwebsite.com",
47-
consumerKey: "ck_your_consumer_key",
48-
consumerSecret: "cs_your_consumer_secret"
49-
);
50-
51-
/// Get data using the endpoint
52-
var p = await wc_api.getAsync("products");
53-
return p;
54-
}
55-
56-
@override
57-
void initState() {
58-
super.initState();
59-
}
60-
61-
@override
62-
Widget build(BuildContext context) {
63-
return new Scaffold(
64-
appBar: new AppBar(
65-
title: new Text(widget.title),
66-
),
67-
body: FutureBuilder(
68-
future: getProducts(),
69-
builder: (_, s){
70-
71-
if(s.data == null){
72-
return Container(
73-
child: Center(
74-
child: Text("Loading..."),
75-
),
76-
);
77-
}
78-
79-
return ListView.builder(
80-
itemCount: s.data.length,
81-
itemBuilder: (_, index){
82-
83-
/// create a list of products
84-
return ListTile(
85-
leading: CircleAvatar(
86-
child: Image.network(s.data[index]["images"][0]["src"]),
87-
),
88-
title: Text(s.data[index]["name"]),
89-
subtitle: Text("Buy now for \$ " + s.data[index]["price"]),
90-
);
91-
92-
}
93-
);
94-
},
95-
),
96-
);
97-
}
9+
### GET request (Fetch products)
10+
```dart
11+
Future getProducts() async {
12+
// Initialize the API
13+
WooCommerceAPI wooCommerceAPI = WooCommerceAPI(
14+
url: "https://www.yourwebsite.com",
15+
consumerKey: "ck_your_consumer_key",
16+
consumerSecret: "cs_your_consumer_secret");
17+
18+
// Get data using the "products" endpoint
19+
var products = await wooCommerceAPI.getAsync("products");
20+
return products;
9821
}
99-
10022
```
23+
You can find a full example [here](example/fetch_products.dart)
10124

102-
### Example of making a POST (Create a customer)
25+
### POST request (Create a customer)
10326
```dart
10427
Future createCustomer() async {
10528
try {

0 commit comments

Comments
 (0)