搜尋套件、儲存庫與 APP 分類

套件詳情v4.2.0

shopify_flutter

一個用於將您的 Shopify 商店與應用程式無縫連接的 Flutter 套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2510
喜歡數
81
Pub 分數
150

安裝套件

flutter pub add shopify_flutter

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

shopify_flutter 套件可實現 Flutter 應用程式與 Shopify 商店之間的無縫整合。它提供簡單的 API,可用於取得產品、管理購物車、處理訂單及處理驗證,讓開發者能輕鬆建構從 Shopify 即時獲取資料的電商應用。此套件專為希望將其應用程式直接連結至 Shopify 生態系統的開發者設計,支援 Android、iOS、Web、macOS、Windows 及 Linux 等多個平台。該套件簡化常見的電商工作流程,同時維持跨裝置的相容性。

適用情境

  • 建構基於 Shopify 的行動應用程式
  • 將產品目錄整合到Flutter應用中
  • 啟用應用內結帳功能
  • 同步庫存數據
  • 建立自訂商店

主要特色

  • 直接 Shopify API 連接
  • 多平台支援
  • 產品和購物車管理
  • 身份驗證處理
  • 即時資料同步

適合對象

  • Flutter 開發人員建構電子商務應用
  • 與 Shopify 商店整合的團隊
  • 需要產品和訂單管理的應用

使用建議

  • 需要有效的 Shopify 商店憑證
  • 依賴網路連接
  • 需要對API回應進行適當的錯誤處理
  • 可能需要額外的UI組件才能實現完整功能

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

shopify_flutter

Analyzer status

A flutter package that works as a bridge between your Shopify Store and Flutter Application.

Support

If you like the package and find it helpful, you can Buy Me MO:MO.

How To Use

Create a private app on your Shopify store. Please follow THIS DOC to get started with it.

While creating storefront api access token, makes sure to check all the api permissions as some queries and mutations require permission on objects like product tags.

First of all configure the ShopifyConfig like that:

void main() {
  
  ShopifyConfig.setConfig(
    storefrontAccessToken: '*******************',
    storeUrl: '*****.myshopify.com',

    // Optional | Needed only if needed to call admin api
    adminAccessToken: "shpat_*******************", 

    // optional | default: 2026-07
    storefrontApiVersion: '2026-07',

    // optional | default: null
    cachePolicy: CachePolicy.cacheAndNetwork,

     // Store locale | default : en
    language: 'en',

    // optional | default: in-memory GraphQLCache()
    // Inject a custom GraphQLCache for the Storefront client (e.g. disk-backed
    // via HiveStore from graphql_flutter).
    storefrontCache: GraphQLCache(store: await HiveStore.open()),

    // optional | default: in-memory GraphQLCache()
    // Inject a custom GraphQLCache for the Admin client.
    adminCache: GraphQLCache(store: await HiveStore.open(boxName: 'admin')),

    // optional | default: 30s
    queryRequestTimeout: const Duration(seconds: 30)
  );
  
  runApp(MyApp());
}

adminAccessToken is only required for admin api calls like deleteCustomer(). If you are not using that function, you may not need to provide it.

storefrontApiVersion default vesion is set to '2026-07'. This package requires 2026-07 or newer (the cart operations rely on fields added in 2026-07). Shopify supports each version for 12 months after release and then falls forward to the oldest supported version, so prefer keeping this current.

language defaults to 'en'. It is the default locale/language of the store. Only takes effect if the store supports provided language code.

storefrontCache / adminCache let you supply a GraphQLCache from graphql_flutter so query results can be persisted to disk (e.g. via HiveStore) and survive app restarts. When omitted, fresh in-memory caches are created as before.


These are the possible instances, each contains different methods which will help you with working with the Shopify Storefront API.

The goal is to make creating an mobile app from your Shopify website easier.

Error handling

Every method throws a ShopifyException when a call fails — whether Shopify returned GraphQL/user errors, or the request never completed (no connectivity, timeout, HTTP error). One catch covers both:

try {
  final products = await ShopifyStore.instance.getAllProducts();
} on ShopifyException catch (e) {
  // e.key       -> the operation, e.g. 'cartLinesAdd'
  // e.errorKey  -> the kind of error, e.g. 'userErrors'
  // e.errors    -> the messages Shopify returned
  print(e);
}

ShopifyException is exported from package:shopify_flutter/shopify_flutter.dart.

Changed in 3.1.0. Failed requests previously threw a bare String — which is not an Exception, so on Exception catch did not catch it, and for connectivity errors the thrown value was an empty string with the real cause discarded. If you relied on catching a String, switch to ShopifyException. Code using a bare catch (e) keeps working.

Shopify Auth
  ShopifyAuth shopifyAuth = ShopifyAuth.instance;

  Future<ShopifyUser> signInWithEmailAndPassword({
    required String email, 
    required String password
  })

  Future<ShopifyUser> createUserWithEmailAndPassword({
    required String email, 
    required String password, 
    String? phone, 
    String? firstName, 
    String? lastName, 
    bool? acceptsMarketing
  })

  Future<void> signOutCurrentUser()

  Future<void> sendPasswordResetEmail({required String email})

  Future<ShopifyUser?> currentUser({bool forceRefresh = false})

  Future<void> deleteCustomer({required String userId})

  Future<String?> get currentCustomerAccessToken

  Future<bool> get isAccessTokenExpired

  Future<AccessTokenWithExpDate?> get accessTokenWithExpDate
Shopify Store
  ShopifyStore shopifyStore = ShopifyStore.instance;

  Future<List<Product>> getProductsByIds(List<String> productIds)

  Future<List<ProductVariant>> getVariantsByIds(List<String> idList)

  Future<List<Product>> getXProductsAfterCursor(
    int limit,
    String startCursor
  )

  Future<List<Product>> getAllProducts()

  Future<List<Product>> getNProducts({
    required int n, 
    required SortKey sortKey
  })

  Future<Shop> getShop()

  Future<Collection?> getCollectionById(String collectionId)

  Future<List<Collection>> getAllCollections()

  Future<List<Product>> getAllProductsFromCollectionById(String id)

  Future<List<Product>> getAllProductsOnQuery(
    String cursor, 
    SortKeyProduct sortKey, 
    String query
  )

  Future<List<Product>> getXProductsOnQueryAfterCursor(
    String cursor, 
    int limit, 
    SortKeyProduct sortKey, 
    String query
  )

  /// filters available queries
  Future<List<Product>> getXProductsAfterCursorWithinCollection(
    String id, 
    int limit, 
    String startCursor, 
    SortKeyProduct sortKey, 
    Map<String, dynamic>? filters
  )

  Future<List<Product>> searchProducts(
    String query, 
    {
      int limit = 15, 
      String? startCursor, 
      SearchSortKeys sortKey = 
      SearchSortKeys.RELEVANCE, 
      bool reverse = false, 
      Map<String, dynamic>? filters
    }
  )

Example to get metafields in product

      final products = await shopifyStore.getProductsByIds(
        [id],
        metafields: [
          MetafieldIdentifier(key: 'content-about-the-brand', namespace: 'pim'),
          MetafieldIdentifier(key: 'pdp_content_image_1_mobile', namespace: 'custom'),
          MetafieldIdentifier(key: 'pdp_content_image_2_mobile', namespace: 'custom'),
          MetafieldIdentifier(key: 'pdp_content_image_3_mobile', namespace: 'custom'),
          //...
        ],
      );
Shopify Cart
  ShopifyCart shopifyCart = ShopifyCart.instance;

  Future<Cart?> getCartById(String cartId, {bool reverse = false})

  Future<Cart> createCart(CartInput cartInput)

  Future<Cart> addLineItemsToCart({
    required String cartId, 
    required List<CartLineInput> cartLineInputs,
    bool reverse = false,
  })

  Future<Cart> removeLineItemsFromCart({
    required String cartId, 
    required List<String> lineIds,
    bool reverse = false,
  })

  Future<Cart> updateLineItemsInCart({ 
    required String cartId, 
    required List<CartLineInput> cartLineInputs,
    bool reverse = false,
  })

  Future<Cart> updateNoteInCart({ 
    required String cartId, 
    required String note,
    bool reverse = false,
  })

  Future<Cart> updateCartDiscountCodes({ 
    required String cartId, 
    required List<String> discountCodes,
    bool reverse = false,
  })

  /// Adds delivery addresses to an existing cart.
  /// Replaces the removed `buyerIdentity.deliveryAddressPreferences`.
  Future<Cart> addDeliveryAddresses({
    required String cartId,
    required List<CartSelectableAddressInput> addresses,
    bool reverse = false,
  })

  Future<Cart> updateBuyerIdentityInCart({ 
    required String cartId, 
    required CartBuyerIdentityInput buyerIdentity,
    bool reverse = false,
  })

  Future<Cart> updateCartAttributes({
    required String cartId,
    required List<AttributeInput> attributes,
    bool reverse = false,
  })
Shopify Order
  ShopifyOrder shopifyOrder = ShopifyOrder.instance;

  Future<List<Order>> getAllOrders({String customerAccessToken})
Shopify Customer
  ShopifyCustomer shopifyCustomer = ShopifyCustomer.instance;

  Future<void> customerAddressUpdate({
    required String customerAccessToken,
    required String id,
    String? address1, 
    String? address2, 
    String? company, 
    String? city, 
    String? country, 
    String? firstName, 
    String? lastName, 
    String? phone, 
    String? province, 
    String? zip, 
  })

  Future<void> customerUpdate({
    String? email, 
    String? firstName, 
    String? lastName, 
    String? password, 
    String? phoneNumber, 
    String? customerAccessToken, 
    bool? acceptsMarketing
  })

  Future<Address> customerAddressCreate({
    String? address1, 
    String? address2, 
    String? company, 
    String? city, 
    String? country, 
    String? firstName,
    String? lastName, 
    String? phone, 
    String? province, 
    String? zip, 
    String? customerAccessToken
  })


  Future<void> customerAddressDelete({
    String? customerAccessToken, 
    String? addressId
  })

  Future<void> customerDefaultAddressUpdate({
    required String addressId, 
    required String customerAccessToken
  })
Shopify Blog
  ShopifyBlog shopifyBlog = ShopifyBlog.instance;

  Future<List<Blog>> getAllBlogs()

  Future<Blog> getBlogByHandle(
    String handle, 
    SortKeyArticle sortKeyArticle
  )

  Future<List<Article>> getXArticlesSorted({
    int articleAmount, 
    SortKeyArticle sortKeyArticle
  })
Shopify Page
  ShopifyPage shopifyPage = ShopifyPage.instance;

  Future<List<Page>> getAllPages()

  Future<Page> getPageByHandle(String handle)
Shopify Localization
  ShopifyLocalization shopifyLocalizatoin = ShopifyLocalization.instance;

  Future<Localization> getLocalization()

  // Used to change currency units. eg: "US", "NP", "JP" etc. Only takes effect if the store supports provided currency.
  void setCountryCode(String? countryCode)

  // Used to set language code, eg: "EN", "DE", "FIL", "ZH_CN" etc.
  void setLanguageCode(String? languageCode)

  // Getters
  countryCode // get the stored country code
  languageCode // get the stored language code

Shopify Custom
  ShopifyCustom shopifyCustom = ShopifyCustom.instance;

  Future<Map<String, dynamic>?> customQuery({
    required String gqlQuery, 
    Map<String, dynamic> variables = const {}, 
    bool adminAccess = false
  })

  Future<Map<String, dynamic>?> customMutation({
    required String gqlMutation, 
    Map<String, dynamic> variables = const {}, 
    bool adminAccess = false
  })

Above you see the instance on top and the possible methods and functions which you can use.


Filter Products

filters is a Map of String and dynmaic. Filter by price and availability are availabe by default.

Example:

  1. gets products with a price between 100 and 500
  {"price": {"min":100, "max":500} } 
  
  2. gets products with a price between 100 and 500 which are available
  {"price": {"min":100, "max":500}, "available": true} } 

  3. gets products with a variant option with name "color" and value "blue"
  { "variantOption": { "name": "color", "value": "blue" } } 
Configure Filters

Configure Filters

For more information about filters visit:

  1. https://shopify.dev/docs/custom-storefronts/building-with-the-storefront-api/products-collections/filter-products#step-1-query-products

  2. https://shopify.dev/docs/api/storefront/2026-07/input-objects/productfilter


Contribution

Everybody can contribute and is invited to do so!

Important: If you add a new field to a model please consider also adding this to every mutation/query that is associated with the model.

Example: adding a new field to Cart means going through every cart query/mutation in lib/graphql_operations/storefront/ and adding it to each one. (adding a new field to a Model also requires you to update the fromJson)

所屬分類

依賴

依賴清單 5 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。