woocommerce 0.9.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

woocommerce #

Woocommerce SDK for Flutter.

Getting Started #

Add the package to your pubspec.yaml and import.

import 'package:woocommerce/woocommerce.dart';

Create an instance of WooCommerce for your project.


WooCommerce woocommerce = WooCommerce(
  baseUrl: yourBaseUrl,
  consumerKey: yourConsumerKey,
  consumerSecret: consumerSecret);

Parameter, [baseUrl] is the base url of your site. For example, http://me.com, https://me.com or http://my.me.com

Parameter [consumerKey] is the consumer key provided by WooCommerce, e.g. ck_12abc34n56j.

Parameter [consumerSecret] is the consumer secret provided by WooCommerce, e.g. cs_1uab8h3s3op.

Optional Parameter [apiPath] is the direct url from your baseUrl to your Woo commerce endpoint. An example : "/wp-json/wc/v3/" This is useful if only you changed your default Wordpress Woocommerce path, otherwise default applies.

Optional Parameter [isDebug], tells the library if it should print to debug logs. /// Useful if you are debuging or in development.

The goal of Woo Commerce SDK is to make building amazing Ecommerce apps with flutter and Woo Commerce as easy as can be, hope it improves your workflow.

Features. #

  • User Authentication.
  • Customer Management
  • Cart Management.
  • Order Management.
  • Products management.
  • Categories.
  • Tags.
  • Variations.
  • Ability to filter on methods that returns a list.
  • Supports custom endpoints.
  • Shipping, Shipping methods, Shipping Locations.
  • Payment.
  • Tax, TaxClasses.
  • Etc and more.

Notes. #

Install Jwt Token Plugin and Wp Rest User, to be able to log in,

Examples #

Put your credentials into the example app for a quick demo.


Auth #

//Login - Returns the access token on success.

final token = woocommerce.authenticateViaJWT(username: username, password: password);

// Login - Signs a user in and returns the logged in user's (WooUser object) details.

final user = woocommerce.loginUser(username: username, password: password);

/// Create Account
// Recommended, create a new Wordpress user and returns whether action was successful or not using WP Rest User Wordpress plugin.
Woouser user = WooUser(username: username, password: password, email: email);
bool result = woocommerce.registerNewUser(user);

// Creates a new Woocommerce customer and returns the WooCustomer object.
WooCustomer user = WooCustomer(username: username, password: password, email: email);
final result = woocommerce.createCustomer();

// Return current loggedIn user (WooUser object).

final user = woocommerce.fetchLoggedInUser();

Products see SDK reference for filter options. #

// Get All Products - Returns list of product object, default is 10 per page.

final myProducts = await woocommerce.getProducts();

//Get All Featured Products - Returns a list of featured products, see Api reference for more filter options.

final myFeaturedProducts = await woocommerce.getProducts(featured: true);

// Get All Products marked with category id '22'.

final mySpecificProduct = await getProducts(category: '22');

Cart! #

// Add To Cart! - Returns the added cart item object(Accepts quantity, product id, and list of variations(id) of the product to be added)

final myCart = await woocommerce.addToCart(quantity: 2, id: 17);

// Create an Order. - Returns the created order object (Accepts an orderPayload object).

OrderPayload orderPayload = OrderPayload(customerId: customerId, setPaid=true);
final order = await woocommerce.CreateOrder(orderPayload);

Custom Requests - Make your custom authenticated requests to the Woocommerce api. #

final response = await woocommerce.put(endpoint, data);

final anotherResponse = await woocommerce.get(endpoint);

Updates #

  • [x] Add documentation.
  • [ ] Add more search filter abilities.
  • [ ] Multiple Examples.

WooCommerce SDK Documentation Reference #

[WooCommerce SDK Docs] (https://pub.dev/documentation/woocommerce/latest/)

WooCommerce Api Documentation Reference #

[WooCommerce Docs] (https://woocommerce.github.io/woocommerce-rest-api-docs/)

Issues and FeedBack #

If you find this useful 💙, feel free to click ⭐ You can create a Github issue anytime. Pull requests on both code and documentation are welcomed as well pls 😍. You can also send a mail to ray@flutterengineer.com.

For help getting started with Flutter, view the online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Change Log #

[0.0.1] - UnReleased. #

[0.7.0] - initial publish. #

  • Authentication
  • Documentation
  • Custom Requests
  • Made Most Get and Create Methods available for the following features.
  • Customer / User Authentication.
  • Cart Management.
  • Order Management.
  • Products management.
  • Categories.
  • Tags.
  • Variations.
  • Ability to filter on methods that returns a list.
  • Supports custom endpoints.
  • Shipping.
  • Tax, TaxClasses.
  • Etc and more.

[0.9.0] - publish. #

  • Fix Customer Registration.
  • Documentation
  • Add example.
  • made put and delete methods available.
  • ready for use.


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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'WooCommerce Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      home: MyHomePage(title: "Woo Commerce Demo"),

String baseUrl = "";
String consumerKey = "";
String consumerSecret = "";

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

  final String title;

  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {

  List<WooProduct> products = [];
  List<WooProduct> featuredProducts = [];
  WooCommerce wooCommerce = WooCommerce(
    baseUrl: baseUrl,
    consumerKey: consumerKey,
    consumerSecret: consumerSecret,
    isDebug: true,

  getProducts() async{
    products = await wooCommerce.getProducts();
    setState(() {

  void initState() {
    //You would want to use a feature builder instead.

  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    final double itemHeight = (size.height - kToolbarHeight - 24) / 2;
    final double itemWidth = size.width / 2;
        body: SafeArea(
          child: CustomScrollView(
            slivers: <Widget>[
                child: Container(
                  margin: EdgeInsets.all(10),
                  child: Text('My Awesome Shop',
                    style: Theme.of(context).textTheme.headline.apply(color: Colors.blueGrey),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 2,
                  childAspectRatio: (itemWidth / itemHeight),
                  mainAxisSpacing: 2,
                  crossAxisSpacing: 1,

                delegate: SliverChildBuilderDelegate(
                      (BuildContext context, int index) {
                        final product = products[index];
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: <Widget>[
                            height: 230,
                            width: 200,
                            margin: EdgeInsets.all(10),
                            decoration: BoxDecoration(
                              image: DecorationImage(image: NetworkImage(product.images[0].src,),
                                  fit: BoxFit.cover),
                              color: Colors.pinkAccent,
                              borderRadius: BorderRadius.all(Radius.circular(10)),
                            //child: Image.network(product.images[0].src, fit: BoxFit.cover,),
                          Text(product.name?? 'Loading...', style: Theme.of(context).textTheme.title.apply(color: Colors.blueGrey),),
                          Text('\$'+product.price?? '', style: Theme.of(context).textTheme.subtitle,)
                  childCount: products.length,

Use this package as a library

1. Depend on it

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

  woocommerce: ^0.9.0

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/woocommerce.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart


  • woocommerce that is a package requiring null.

Package not compatible with runtime flutter-web on web


  • package:woocommerce/woocommerce.dart that imports:
  • dart:io

Health suggestions

Fix lib/models/products.dart. (-0.50 points)

Analysis of lib/models/products.dart reported 1 hint:

line 297 col 1: Prefer using /// for doc comments.

Format lib/constants/constants.dart.

Run flutter format to format lib/constants/constants.dart.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Fix additional 25 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/models/cart.dart (Run flutter format to format lib/models/cart.dart.)
  • lib/models/cart_item.dart (Run flutter format to format lib/models/cart_item.dart.)
  • lib/models/coupon.dart (Run flutter format to format lib/models/coupon.dart.)
  • lib/models/customer.dart (Run flutter format to format lib/models/customer.dart.)
  • lib/models/customer_download.dart (Run flutter format to format lib/models/customer_download.dart.)
  • lib/models/jwt_response.dart (Run flutter format to format lib/models/jwt_response.dart.)
  • lib/models/order.dart (Run flutter format to format lib/models/order.dart.)
  • lib/models/order_payload.dart (Run flutter format to format lib/models/order_payload.dart.)
  • lib/models/payment_gateway.dart (Run flutter format to format lib/models/payment_gateway.dart.)
  • lib/models/product_attribute_term.dart (Run flutter format to format lib/models/product_attribute_term.dart.)
  • lib/models/product_attributes.dart (Run flutter format to format lib/models/product_attributes.dart.)
  • lib/models/product_category.dart (Run flutter format to format lib/models/product_category.dart.)
  • lib/models/product_review.dart (Run flutter format to format lib/models/product_review.dart.)
  • lib/models/product_shipping_class.dart (Run flutter format to format lib/models/product_shipping_class.dart.)
  • lib/models/product_tag.dart (Run flutter format to format lib/models/product_tag.dart.)
  • lib/models/product_variation.dart (Run flutter format to format lib/models/product_variation.dart.)
  • lib/models/shipping_method.dart (Run flutter format to format lib/models/shipping_method.dart.)
  • lib/models/shipping_zone.dart (Run flutter format to format lib/models/shipping_zone.dart.)
  • lib/models/shipping_zone_location.dart (Run flutter format to format lib/models/shipping_zone_location.dart.)
  • lib/models/shipping_zone_method.dart (Run flutter format to format lib/models/shipping_zone_method.dart.)
  • lib/models/tax_classes.dart (Run flutter format to format lib/models/tax_classes.dart.)
  • lib/models/tax_rate.dart (Run flutter format to format lib/models/tax_rate.dart.)
  • lib/models/user.dart (Run flutter format to format lib/models/user.dart.)
  • lib/utilities/local_db.dart (Run flutter format to format lib/utilities/local_db.dart.)
  • lib/woocommerce.dart (Run flutter format to format lib/woocommerce.dart.)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
crypto ^2.1.3 2.1.5
flutter 0.0.0
http ^0.12.1 0.12.1
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
http_parser 3.1.4
meta 1.1.8 1.2.2
path 1.7.0
pedantic 1.9.0 1.9.2
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies