fast_sdk 0.0.1 copy "fast_sdk: ^0.0.1" to clipboard
fast_sdk: ^0.0.1 copied to clipboard

Fast SDK for Flutter

example/lib/main.dart

import 'dart:async';
import 'package:fast_sdk/fast.dart';
import 'package:fast_sdk/generated_fast_api.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.deepPurple,
      ),
      home: const MyHomePage(title: 'Fast checkout'),
    );
  }
}

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Future<void> _configure() async {
    String appId = 'f864c369-e470-40ac-81ad-df2cd3c7f44c'; // staging
    Fast.configure(appId);
  }

  void _checkoutWithProducts() {
    // staging
    const productId = '119';
    const variantId = '175';

    var products = List<Product>.empty(growable: true);
    products.add(Product(
        id: productId,
        variantId: variantId,
        productOptions: null,
        quantity: 1));

    Fast.checkoutWithProducts(products, 'USD', null, (fastEvent) {
      String fastEventType = fastEvent.eventType?.toString() ?? "";
      String purchaseInfo = fastEvent.purchaseInfo?.toString() ?? "";
      String error = fastEvent.error?.toString() ?? "";
      print(
          "Subscription received event in dart/example: type: $fastEventType, purchaseInfo: $purchaseInfo, error: $error");
    });
  }

  void _checkoutWithCartId() {
    const cartId = 'b7b49c96-5c76-44de-b937-e7a7bc3915d8'; // staging
    Fast.checkoutWithCartId(cartId, 'USD', (fastEvent) {
      String fastEventType = fastEvent.eventType?.toString() ?? "";
      String purchaseInfo = fastEvent.purchaseInfo?.toString() ?? "";
      String error = fastEvent.error?.toString() ?? "";
      print(
          "Subscription received event in dart/example: type: $fastEventType, purchaseInfo: $purchaseInfo, error: $error");
    });
  }

  void _reset() {
    Fast.reset();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            MaterialButton(
                onPressed: _configure,
                color: const Color(0xFF000000),
                height: 48.0,
                shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(6.0))),
                padding: const EdgeInsets.only(
                    left: 16.0, top: 8.0, right: 16.0, bottom: 8.0),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text('Configure',
                        style: Theme.of(context)
                            .textTheme
                            .button
                            ?.copyWith(color: const Color(0xFFFFFFFF))),
                  ],
                )),
            MaterialButton(
                onPressed: _checkoutWithProducts,
                color: const Color(0xFF000000),
                height: 48.0,
                shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(6.0))),
                padding: const EdgeInsets.only(
                    left: 16.0, top: 8.0, right: 16.0, bottom: 8.0),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text('Checkout with Products',
                        style: Theme.of(context)
                            .textTheme
                            .button
                            ?.copyWith(color: const Color(0xFFFFFFFF))),
                  ],
                )),
            MaterialButton(
                onPressed: _checkoutWithCartId,
                color: const Color(0xFF000000),
                height: 48.0,
                shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(6.0))),
                padding: const EdgeInsets.only(
                    left: 16.0, top: 8.0, right: 16.0, bottom: 8.0),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text('Checkout with Cart ID',
                        style: Theme.of(context)
                            .textTheme
                            .button
                            ?.copyWith(color: const Color(0xFFFFFFFF))),
                  ],
                )),
            MaterialButton(
                onPressed: _reset,
                color: const Color(0xFF000000),
                height: 48.0,
                shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(6.0))),
                padding: const EdgeInsets.only(
                    left: 16.0, top: 8.0, right: 16.0, bottom: 8.0),
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text('Sign out',
                        style: Theme.of(context)
                            .textTheme
                            .button
                            ?.copyWith(color: const Color(0xFFFFFFFF))),
                  ],
                )),
          ],
        ),
      ),
    );
  }
}
0
likes
90
pub points
0%
popularity

Publisher

unverified uploader

Fast SDK for Flutter

Homepage

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on fast_sdk