printful 0.0.15 copy "printful: ^0.0.15" to clipboard
printful: ^0.0.15 copied to clipboard

A Flutter plugin for seamless integration with the Printful API. Manage products, orders, shipping rates, and tracking directly in your Flutter apps with native Android & iOS support. Perfect for buil [...]

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    // Printful.instance.setBearerToken(
    //   token: 'byly0vFucP4e5DKeLMl3gTVXuLmNedge8SIfii3M',
    // );
    Printful.instance.configPublicApp(
      clientId: 'app-3147029',
      clientSecret:
          'QYMREwCPJ0Bc3QQsDtCHZTorEj9SLREohHZcgpqQnWt0mR6TlE6PXTGSbXccTHiX',
    );
    Printful.instance.setHeaderStoreId(storeId: '16592825');
    super.initState();
  }

  custom() async {
    Printful.instance.setBearerToken(
      token: 'lKUQzDvxfwJ5yU9ujyVhZ80FCGE7A6A8cbXfNJBB',
    );
    final r1 =
        await Printful.instance.STORE_INFORMATION_API
            .getBasicInformationAboutStores();
    for (final r in r1.result) {
      debugPrint('>>> ${r.toJson()}');
    }
    // final r2 = await Printful.instance.PRODUCT_API.getSyncProducts();
    // for (final r in r2.result) {
    //   debugPrint('>>> ${r.toJson()}');
    // }
    final r3 = await Printful.instance.PRODUCT_API.getASyncProduct(
      id: 389598310,
    );
    debugPrint('>>> ${r3.result.toJson()}');
  }

  createOrder() async {
    final order = ModifierOrder(
      externalId: '4235234213',
      shipping: 'STANDARD',
      recipient: Address(
        name: 'John Smith',
        company: 'John Smith Inc',
        address1: '19749 Dearborn St',
        address2: 'string',
        city: 'Chatsworth',
        stateCode: 'CA',
        stateName: 'California',
        countryCode: 'US',
        countryName: 'United States',
        zip: '91311',
        phone: '2312322334',
        email: 'firstname.secondname@domain.com',
        taxNumber: '123.456.789-10',
      ),
      items: [
        OrderItem(
          id: 1,
          externalId: 'item-1',
          variantId: 1,
          syncVariantId: 1,
          externalVariantId: 'variant-1',
          warehouseProductVariantId: 1,
          productTemplateId: 1,
          externalProductId: 'template-123',
          quantity: 1,
          price: '13.00',
          retailPrice: '13.00',
          name: 'Enhanced Matte Paper Poster 18×24',
          product: ProductVariant(
            variantId: 3001,
            productId: 301,
            name:
                'Bella + Canvas 3001 Unisex Short Sleeve Jersey T-Shirt with Tear Away Label (White / 4XL)',
            image:
                'https://files.cdn.printful.com/products/71/5309_1581412541.jpg',
          ),

          files: [
            FileAttachment(
              type: 'default',
              url: 'https://example.com/image.jpg',
              options: [FileOption(id: 'template_type', value: 'native')],
              filename: 'shirt1.png',
              visible: true,
              position: FilePosition(
                areaWidth: 1800,
                areaHeight: 2400,
                width: 1800,
                height: 1800,
                top: 300,
                left: 0,
                limitToPrintArea: true,
              ),
            ),
          ],
          options: [ItemOption(id: 'OptionKey', value: 'OptionValue')],
          sku: null,
          discontinued: true,
          outOfStock: true,
        ),
      ],
      retailCosts: OrderRetailCosts(
        currency: 'USD',
        subtotal: '10.00',
        shipping: '5.00',
        discount: '0.00',
        tax: '0.00',
      ),
      gift: OrderGift(subject: 'To John', message: 'Have a nice day'),
      packingSlip: PackingSlip(
        email: 'your-name@your-domain.com',
        phone: '+371 28888888',
        logoUrl: 'http://www.your-domain.com/packing-logo.png',
        storeName: 'Your store name',
        customOrderId: 'kkk2344lm',
        message: 'Thanks for your order!',
      ),
    );
    try {
      final response = await Printful.instance.ORDER_API.createANewOrder(
        modifierOrder: order,
        confirm: false,
        updateExisting: false,
      );
      print(response);
    } catch (e) {
      print(e);
    }
  }

  authorize() async {
    try {
      final tokenResponse = await Printful.instance.OAUTH_API.authorize(
        stateValue: '123',
        redirectUrl: 'https://oauthcallback-dbwq2ilmqq-uc.a.run.app/',
        callbackUrlScheme: 'printful',
      );
      tokenResponse.isValid;
    } catch (e) {
      print(e);
    }
  }

  getBasicInformationAboutStores() async {
    try {
      final response =
          await Printful.instance.STORE_INFORMATION_API
              .getBasicInformationAboutStores();
      print(response);
    } catch (e) {
      print(e);
    }
  }

  getProducts() async {
    try {
      final response = await Printful.instance.CATALOG_API.getProducts();
      for (var e in response.result) {
        print(e.toJson());
      }
    } catch (e) {
      print(e);
    }
  }

  getVariant() async {
    try {
      final response = await Printful.instance.CATALOG_API.getVariant(
        id: 12735,
      );
      print(response);
    } catch (e) {
      print(e);
    }
  }

  getProduct() async {
    try {
      final response = await Printful.instance.CATALOG_API.getProduct(id: 528);
      print(response.result.toJson());
    } catch (e) {
      print(e);
    }
  }

  getProductSizeGuide() async {
    try {
      final response = await Printful.instance.CATALOG_API.getProductSizeGuide(
        id: 528,
      );
      print(response);
    } catch (e) {
      print(e);
    }
  }

  getCategories() async {
    try {
      final response = await Printful.instance.CATALOG_API.getCategories();
      for (var e in response.result) {
        print(e.toJson());
      }
    } catch (e) {
      print(e);
    }
  }

  getCategory() async {
    try {
      final response = await Printful.instance.CATALOG_API.getCategory(id: 1);
      print(response);
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SizedBox(
          width: double.infinity,
          child: Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              ElevatedButton(onPressed: custom, child: Text('custom')),
              ElevatedButton(onPressed: authorize, child: Text('authorize')),
              ElevatedButton(
                onPressed: getProducts,
                child: Text('getProducts'),
              ),
              ElevatedButton(onPressed: getVariant, child: Text('getVariant')),
              ElevatedButton(onPressed: getProduct, child: Text('getProduct')),
              ElevatedButton(
                onPressed: getProductSizeGuide,
                child: Text('getProductSizeGuide'),
              ),
              ElevatedButton(
                onPressed: getCategory,
                child: Text('getCategory'),
              ),
              ElevatedButton(
                onPressed: getCategories,
                child: Text('getCategories'),
              ),
              ElevatedButton(
                onPressed: createOrder,
                child: Text('createOrder'),
              ),
              ElevatedButton(
                onPressed: getBasicInformationAboutStores,
                child: Text('getBasicInformationAboutStores'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
0
points
24
downloads

Publisher

verified publishermgorki.id.vn

Weekly Downloads

A Flutter plugin for seamless integration with the Printful API. Manage products, orders, shipping rates, and tracking directly in your Flutter apps with native Android & iOS support. Perfect for building custom e-commerce, print-on-demand, or dropshipping solutions.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, flutter, flutter_secure_storage, flutter_web_auth_2, get_it, json_annotation, logger, retrofit

More

Packages that depend on printful