Using WooCommerce with Flutter


Installing

Add this to your app dependencies in pubspec.yaml

woosignal: ^3.0.1

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

// Initialize WooSignal
await WooSignal.instance.init(appKey: "your app key");

// Call API
List<Product> products = await WooSignal.instance.getProducts();

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 = "";

  _incrementCounter() async {
    // Create an instance
    WooSignal wooSignal = await WooSignal.instance.init(appKey: "your app key");

    // Call API
    List<Product> products = await WooSignal.instance.getProducts();

    if (products.length > 0) {
      _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),
      ),
    );
  }
}