shopify_flutter

Analyzer status

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

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',
    adminAccessToken: "shpat_*******************", // Optional | Needed only if needed to call admin api
    storefrontApiVersion: '2023-07', // optional | default: 2023-07
    cachePolicy: CachePolicy.cacheAndNetwork, // optional | default: null
    language: 'en' // Store locale | default : en
  );
  
  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 '2023-07'

language defaults to 'en'. It is the default locale/language of the store


These are the five 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.

Shopify Auth
  ShopifyAuth shopifyAuth = ShopifyAuth.instance;

  Future<ShopifyUser> signInWithEmailAndPassword({required String email, required String password})
  Future<ShopifyUser> createUserWithEmailAndPassword({required String firstName, required String lastName, required String email, required String password, String? phone, bool? acceptsMarketing})
  Future<void> signOutCurrentUser()
  Future<void> sendPasswordResetEmail({required String email})
  Future<ShopifyUser> currentUser()
  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()
  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})
Shopify Checkout
  ShopifyCheckout shopifyCheckout = ShopifyCheckout.instance;

  Future<Checkout> getCheckoutInfoQuery({String checkoutId})
  Future<Checkout> getCheckoutInfoWithAvailableShippingRatesQuery({String checkoutId})
  Future<List<Order>> getAllOrders({String customerAccessToken})
  Future<void> checkoutLineItemsReplace({String checkoutId, List<Map<String,dynamic>> checkoutLineItems})
  Future<void> checkoutCustomerAssociate({String checkoutId, String customerAccessToken}) 
  Future<void> checkoutCustomerDisassociate({String checkoutId})
  Future<void> checkoutDiscountCodeApply({String checkoutId, String discountCode})
  Future<void> checkoutDiscountCodeRemove({String checkoutId})
  Future<Checkout> createCheckout()
  Future<void> checkoutGiftCardAppend(String checkoutId, List<String> giftCardCodes)
  Future<void> checkoutGiftCardRemove(String appliedGiftCardId, String checkoutId)
  Future<void> shippingLineUpdate(String checkoutId, String shippingRateHandle)
  Future<void> checkoutCompleteFree(String checkoutId)
  Future<void> updateAttributes(String checkoutId, {bool allowPartialAddresses, Map<String, String> customAttributes, String note})
  Future<Checkout> updateCheckoutEmail(String checkoutId, String email)
Shopify Customer
  ShopifyCustomer shopifyCustomer = ShopifyCustomer.instance;

  Future<void> customerAddressUpdate({String address1, String address2, String company, String city, String country, String firstName, String lastName, String phone, String province, String zip, String customerAccessToken, id})
  Future<void> customerUpdate({String email, String firstName, String lastName, String password, String phoneNumber, String customerAccessToken, bool acceptsMarketing})
  Future<void> 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 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/2023-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 Checkout which is the webUrl, now you will need to go through the various queries/mutations and search for "Checkout" and add webUrl to each one of those. (adding a new field to a Model also requires you to update the fromJson)

Libraries

enums/enums
enums/src/payment_token_type
enums/src/sort_key_article
enums/src/sort_key_blog
enums/src/sort_key_collection
enums/src/sort_key_order
enums/src/sort_key_page
enums/src/sort_key_product
enums/src/sort_key_product_collection
graphql_operations/admin/mutations/customer_delete
graphql_operations/storefront/mutations/access_token_delete
graphql_operations/storefront/mutations/checkout_associate_customer
graphql_operations/storefront/mutations/checkout_attributes_update
graphql_operations/storefront/mutations/checkout_complete_free
graphql_operations/storefront/mutations/checkout_complete_with_credit_card
graphql_operations/storefront/mutations/checkout_customer_disassociate
graphql_operations/storefront/mutations/checkout_discount_code_apply
graphql_operations/storefront/mutations/checkout_discount_code_remove
graphql_operations/storefront/mutations/checkout_email_update
graphql_operations/storefront/mutations/checkout_giftcard_remove
graphql_operations/storefront/mutations/checkout_giftcards_append
graphql_operations/storefront/mutations/checkout_line_item_add
graphql_operations/storefront/mutations/checkout_line_item_remove
graphql_operations/storefront/mutations/checkout_line_item_update
graphql_operations/storefront/mutations/checkout_line_items_replace
graphql_operations/storefront/mutations/checkout_shipping_address_update
graphql_operations/storefront/mutations/checkout_shipping_line_update
graphql_operations/storefront/mutations/complete_checkout_free
graphql_operations/storefront/mutations/complete_checkout_token_v3
graphql_operations/storefront/mutations/create_checkout
graphql_operations/storefront/mutations/customer_access_token_create
graphql_operations/storefront/mutations/customer_access_token_create_with_multipass
graphql_operations/storefront/mutations/customer_access_token_renew
graphql_operations/storefront/mutations/customer_address_create
graphql_operations/storefront/mutations/customer_address_delete
graphql_operations/storefront/mutations/customer_address_update
graphql_operations/storefront/mutations/customer_create
graphql_operations/storefront/mutations/customer_default_address_update
graphql_operations/storefront/mutations/customer_recover
graphql_operations/storefront/mutations/customer_reset
graphql_operations/storefront/mutations/customer_reset_by_url
graphql_operations/storefront/mutations/customer_update
graphql_operations/storefront/queries/get_all_blogs
graphql_operations/storefront/queries/get_all_collections_optimized
graphql_operations/storefront/queries/get_all_orders
graphql_operations/storefront/queries/get_all_pages
graphql_operations/storefront/queries/get_all_products_from_collection_by_id
graphql_operations/storefront/queries/get_all_products_on_query
graphql_operations/storefront/queries/get_blog_by_handle
graphql_operations/storefront/queries/get_checkout_info_is_ready
graphql_operations/storefront/queries/get_checkout_info_requires_shipping
graphql_operations/storefront/queries/get_checkout_info_with_payment_id
graphql_operations/storefront/queries/get_checkout_info_with_payment_id_without_shipping_rates
graphql_operations/storefront/queries/get_checkout_information
graphql_operations/storefront/queries/get_checkout_without_shipping_rates
graphql_operations/storefront/queries/get_collection_by_id
graphql_operations/storefront/queries/get_collections
graphql_operations/storefront/queries/get_collections_by_ids
graphql_operations/storefront/queries/get_customer
graphql_operations/storefront/queries/get_n_articles_sorted
graphql_operations/storefront/queries/get_n_products
graphql_operations/storefront/queries/get_page_by_handle
graphql_operations/storefront/queries/get_product_recommendations
graphql_operations/storefront/queries/get_products
graphql_operations/storefront/queries/get_products_by_handle
graphql_operations/storefront/queries/get_products_by_ids
graphql_operations/storefront/queries/get_shop
graphql_operations/storefront/queries/get_web_url
graphql_operations/storefront/queries/get_x_collections_and_n_products_sorted
graphql_operations/storefront/queries/get_x_products_after_cursor
graphql_operations/storefront/queries/get_x_products_after_cursor_within_collection
graphql_operations/storefront/queries/get_x_products_on_query_after_cursor
graphql_operations/storefront/queries/search_product
mixins/src/shopify_error
models/json_helper
models/models
models/src/address_autocomplete/address_details/address_details
models/src/address_autocomplete/address_prediction/address_prediction
models/src/address_autocomplete/location_input/location_input
models/src/address_autocomplete/matched_substring/matched_substring
models/src/article/article
models/src/article/articles/articles
models/src/article/author_v_2/author_v_2
models/src/article/comment/comment
models/src/blog/blog
models/src/blog/blogs/blogs
models/src/checkout/applied_gift_cards/applied_gift_cards
models/src/checkout/attribute/attribute
models/src/checkout/available_shipping_rates/available_shipping_rates
models/src/checkout/checkout
models/src/checkout/line_item/line_item
models/src/checkout/line_items/line_items
models/src/checkout/mailing_address/mailing_address
models/src/checkout/product_variant_checkout/product_variant_checkout
models/src/checkout/shipping_rates/shipping_rates
models/src/checkout/tokanized_checkout/tokanized_checkout
models/src/collection/collection
models/src/collection/collections/collections
models/src/order/discount_allocations/discount_allocations
models/src/order/line_item_order/line_item_order
models/src/order/line_items_order/line_items_order
models/src/order/order
models/src/order/orders/orders
models/src/order/shipping_address/shipping_address
models/src/order/successful_fulfillment/successful_fulfilment_tracking_info/successful_fulfilment_tracking_info
models/src/order/successful_fulfillment/successful_fullfilment
models/src/page/page
models/src/page/pages/pages
models/src/product/associated_collections/associated_collections
models/src/product/metafield/metafield
models/src/product/metafield_identifier/metafield_identifier
models/src/product/option/option
models/src/product/price_v_2/price_v_2
models/src/product/product
models/src/product/product_variant/product_variant
models/src/product/products/products
models/src/product/selected_option/selected_option
models/src/product/shopify_image/shopify_image
models/src/product/unit_price_measurement/unit_price_measurement
models/src/shop/payment_settings/payment_settings
models/src/shop/primary_domain/primary_domain
models/src/shop/privacy_policy/privacy_policy
models/src/shop/refund_policy/refund_policy
models/src/shop/shipping_policy/shipping_policy
models/src/shop/shop
models/src/shop/subscription_policy/subscription_policy
models/src/shop/terms_of_service/terms_of_service
models/src/shopify_user/access_token_with_exp_date
models/src/shopify_user/address/address
models/src/shopify_user/addresses/addresses
models/src/shopify_user/last_incomplete_checkout/last_incomplete_checkout
models/src/shopify_user/shopify_user
shopify/shopify
shopify/src/shopify_auth
shopify/src/shopify_blog
shopify/src/shopify_checkout
shopify/src/shopify_custom
shopify/src/shopify_customer
shopify/src/shopify_page
shopify/src/shopify_store
shopify_config
shopify_flutter