Using WooCommerce with Flutter


Installing

Add this to your app dependencies in pubspec.yaml

woosignal: ^1.0.2 

Include package in your dart project

You can install packages from the command line:

$ flutter packages get

Ready to import and use ⚡️

Now in your Dart code, you can use

import 'package:woosignal/woosignal.dart';

// Example getting products
// CONFIG FOR WOOSIGNAL
var wsConfig = {
  "appKey":"your app key",
  "debugMode":true
};

// CREATING AN INSTANCE
WooSignal.getInstance(config: wsConfig).then( (wcStore) {

  wcStore.getProducts().then( (products) {
    print(products[0].name);
  });

});

Using WooSignal WooCommerce

If you've followed the "Get started guide", you should be able to make your first requests.
Go onto the your Flutter application and try the following.

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

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

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

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  String _productName = "";

  void _incrementCounter() {
    setState(() {

      // CONFIG FOR WOOSIGNAL
      var wsConfig = {
        "appKey":"your app key",
        "debugMode":true
      };

      // CREATING AN INSTANCE
      WooSignal.getInstance(config: wsConfig).then( (wcStore) {

        wcStore.getProducts().then( (products) {
          _productName = products[0].name;
          setState(() {

          });
        });

      });

    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(

        title: Text(widget.title),
      ),
      body: Center(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'WooCommerce product :',
            ),
            Text(
              '$_productName',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.lightbulb_outline),
      ),
    );
  }
}