woocommerce_api 0.0.8

WooCommerce SDK for Dart #

A dart package to interact with the WooCommerce API. It uses OAuth1.0a behind the scenes to generate the signature and URL string. It then makes calls and return the data back to the calling function.

Example code and preview

Complete Usage Example #

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:woocommerce_api/woocommerce_api.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'WooCommerce API Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  List<Widget> products = [];

  Future getProducts() async {

    /// Initialize the API
    WooCommerceAPI wc_api = new WooCommerceAPI(
        "https://www.yourwebsite.com",
        "ck_your_consumer_key",
        "cs_your_consumer_secret"
    );
    
    /// Get data using the endpoint
    var p = await wc_api.getAsync("products");
    return p;
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: FutureBuilder(
        future: getProducts(),
        builder: (_, s){

          if(s.data == null){
            return Container(
              child: Center(
                child: Text("Loading..."),
              ),
            );
          }

          return ListView.builder(
            itemCount: s.data.length,
            itemBuilder: (_, index){
            
            /// create a list of products
              return ListTile(
                leading: CircleAvatar(
                  child: Image.network(s.data[index]["images"][0]["src"]),
                ),
                title: Text(s.data[index]["name"]),
                subtitle: Text("Buy now for \$ " + s.data[index]["price"]),
              );

            }
          );
        },
      ),
    );
  }
}

Example of making a POST (Create a customer) #

Future createCustomer() async {
  try {
    var response = await wooCommerceAPI.postAsync(
      "customers",
      {
        "email": 's@c.com',
        "password": "123",
        "billing": {
          "first_name": "Samarth",
        }
      },
    );
    print(response); // JSON Object with response
  } catch (e) {
    print(e);
  }
}

Report any issues if you face any or drop me an email at samarthagarwal@live.com #

[0.0.8]

  • Fixed a bug where POST reuqest could not handle nested JSON data

[0.0.7]

  • Fixed a bug for https websites where consumer_key and consumer_secret params are fixed

[0.0.6]

  • Fixed a fatal bug in types

[0.0.5]

  • Updated to work with HTTPS websites
  • Minor bug fixes
  • Updated ReadMe

[0.0.4]

  • Fixed to work without the query_string package
  • Minor bug fixes

[0.0.3]

  • Updated SDK version upper limit for new Dart version

[0.0.2]

  • Updated docs

[0.0.1]

  • Added getAsync and postAsync functions.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  woocommerce_api: ^0.0.8

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:woocommerce_api/woocommerce_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
78
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
57
Overall:
Weighted score of the above. [more]
80
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/woocommerce_api.dart. (-2.48 points)

Analysis of lib/woocommerce_api.dart reported 5 hints:

line 33 col 23: Name non-constant identifiers using lowerCamelCase.

line 38 col 9: The value of the local variable 'token_secret' isn't used.

line 38 col 9: Name non-constant identifiers using lowerCamelCase.

line 53 col 21: The operator x ~/ y is more efficient than (x / y).toInt().

line 59 col 9: The value of the local variable 'path' isn't used.

Fix lib/query_string.dart. (-0.50 points)

Analysis of lib/query_string.dart reported 1 hint:

line 2 col 3: Prefer using /// for doc comments.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (http).

The package description is too short. (-13 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and woocommerce_api.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <3.0.0
crypto ^2.0.6 2.1.3
flutter 0.0.0
http ^0.11.3+17 0.11.3+17 0.12.0+2
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
http_parser 3.1.3
meta 1.1.7
path 1.6.4
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test