From 820315bd779e3689133c933edee400e91fcdf5b2 Mon Sep 17 00:00:00 2001 From: kammcs <85201048+kammcs@users.noreply.github.com> Date: Sun, 26 Jan 2025 10:45:41 -0500 Subject: [PATCH] Add Metafields to Products and Collections --- example/lib/main.dart | 9 +- example/lib/screens/blog_tab.dart | 7 +- example/lib/screens/cart_tab.dart | 9 +- example/lib/screens/checkout_page.dart | 9 +- example/lib/screens/collection_tab.dart | 18 +- example/lib/screens/home_tab.dart | 3 +- .../lib/screens/product_detail_screen.dart | 3 +- example/lib/screens/shop_tab.dart | 16 +- example/pubspec.lock | 46 ++--- .../get_all_collections_optimized.dart | 19 +- ...et_all_products_from_collection_by_id.dart | 21 ++- .../queries/get_all_products_on_query.dart | 21 ++- .../storefront/queries/get_collections.dart | 19 +- .../queries/get_collections_by_ids.dart | 19 +- .../queries/get_featured_collections.dart | 19 +- .../storefront/queries/get_n_products.dart | 21 ++- .../queries/get_product_by_handle.dart | 19 +- .../queries/get_product_recommendations.dart | 19 +- .../storefront/queries/get_products.dart | 19 +- .../queries/get_products_by_ids.dart | 21 ++- ...t_x_collections_and_n_products_sorted.dart | 36 +++- .../queries/get_x_products_after_cursor.dart | 21 ++- ...oducts_after_cursor_within_collection.dart | 21 ++- .../get_x_products_on_query_after_cursor.dart | 29 ++- .../storefront/queries/search_product.dart | 21 ++- lib/models/json_helper.dart | 4 +- .../address_details/address_details.dart | 3 +- .../address_prediction.dart | 3 +- .../location_input/location_input.dart | 3 +- .../matched_substring/matched_substring.dart | 3 +- lib/models/src/article/article.dart | 16 +- lib/models/src/article/articles/articles.dart | 9 +- .../src/article/author_v_2/author_v_2.dart | 10 +- lib/models/src/article/comment/comment.dart | 3 +- lib/models/src/blog/blogs/blogs.dart | 6 +- .../cart_buyer_identity.dart | 3 +- lib/models/src/cart/cart_cost/cart_cost.dart | 3 +- .../cart_dicount_code/cart_discount_code.dart | 3 +- .../cart_discount_allocation.dart | 3 +- .../cart_delivery_coordinates_preference.dart | 6 +- .../cart_delivery_preference.dart | 3 +- .../cart/cart_preference/cart_preference.dart | 3 +- lib/models/src/cart/customer/customer.dart | 3 +- .../cart_buyer_identity_input.dart | 3 +- .../cart/inputs/cart_input/cart_input.dart | 3 +- .../cart_line_input/cart_line_input.dart | 3 +- .../cart_line_update_input.dart | 3 +- .../delivery_address_input.dart | 3 +- .../mailing_address_input.dart | 3 +- .../lines/cart_line_cost/cart_line_cost.dart | 3 +- lib/models/src/cart/lines/line/line.dart | 11 +- .../applied_gift_cards.dart | 9 +- .../src/checkout/attribute/attribute.dart | 3 +- .../available_shipping_rates.dart | 8 +- lib/models/src/checkout/checkout.dart | 3 +- .../src/checkout/line_item/line_item.dart | 15 +- .../src/checkout/line_items/line_items.dart | 3 +- .../mailing_address/mailing_address.dart | 3 +- .../product_variant_checkout.dart | 3 +- .../shipping_rates/shipping_rates.dart | 8 +- .../tokanized_checkout.dart | 6 +- lib/models/src/collection/collection.dart | 44 ++++- .../src/collection/collection.freezed.dart | 46 ++++- lib/models/src/collection/collection.g.dart | 4 + .../collection/collections/collections.dart | 10 +- .../src/localization/country/country.dart | 3 +- .../src/localization/currency/currency.dart | 3 +- .../src/localization/language/language.dart | 3 +- lib/models/src/localization/localization.dart | 3 +- .../discount_allocations.dart | 6 +- .../line_item_order/line_item_order.dart | 20 +- .../line_items_order/line_items_order.dart | 9 +- lib/models/src/order/order.dart | 13 +- lib/models/src/order/orders/orders.dart | 6 +- .../shipping_address/shipping_address.dart | 3 +- .../successful_fulfilment_tracking_info.dart | 6 +- .../successful_fullfilment.dart | 6 +- lib/models/src/page/pages/pages.dart | 6 +- .../associated_collections.dart | 6 +- .../src/product/metafield/metafield.dart | 19 +- .../product/metafield/metafield.freezed.dart | 66 +++++-- .../src/product/metafield/metafield.g.dart | 4 +- .../metafield_identifier.dart | 3 +- .../src/product/price_v_2/price_v_2.dart | 6 +- lib/models/src/product/product.dart | 141 ++++++-------- lib/models/src/product/product.freezed.dart | 38 +++- lib/models/src/product/product.g.dart | 1 + .../product/product_media/product_media.dart | 7 +- .../product_variant/product_variant.dart | 29 +-- lib/models/src/product/products/products.dart | 8 +- .../selected_option/selected_option.dart | 3 +- .../selling_plan/selling_plan.dart | 3 +- .../selling_plan_option.dart | 3 +- .../selling_plan_allocation.dart | 3 +- .../product/shopify_image/shopify_image.dart | 3 +- .../unit_price_measurement.dart | 3 +- .../payment_settings/payment_settings.dart | 3 +- .../shop/primary_domain/primary_domain.dart | 6 +- .../shop/privacy_policy/privacy_policy.dart | 3 +- .../src/shop/refund_policy/refund_policy.dart | 3 +- .../shop/shipping_policy/shipping_policy.dart | 3 +- .../subscription_policy.dart | 3 +- .../terms_of_service/terms_of_service.dart | 3 +- .../access_token_with_exp_date.dart | 9 +- .../src/shopify_user/address/address.dart | 3 +- .../src/shopify_user/addresses/addresses.dart | 9 +- lib/models/src/shopify_user/shopify_user.dart | 7 +- lib/shopify/src/shopify_auth.dart | 51 ++--- lib/shopify/src/shopify_blog.dart | 20 +- lib/shopify/src/shopify_cart.dart | 47 ++--- lib/shopify/src/shopify_checkout.dart | 177 +++++++----------- lib/shopify/src/shopify_custom.dart | 10 +- lib/shopify/src/shopify_customer.dart | 76 ++++---- lib/shopify/src/shopify_localization.dart | 6 +- lib/shopify/src/shopify_order.dart | 3 +- lib/shopify/src/shopify_page.dart | 3 +- lib/shopify/src/shopify_store.dart | 167 ++++++++++------- 117 files changed, 971 insertions(+), 823 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 594c0b18..61183514 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -77,16 +77,13 @@ class MyHomePageState extends State { unselectedItemColor: Colors.black, items: const [ BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'), - BottomNavigationBarItem( - icon: Icon(Icons.category), label: 'Collections'), + BottomNavigationBarItem(icon: Icon(Icons.category), label: 'Collections'), BottomNavigationBarItem(icon: Icon(Icons.search), label: 'Search'), BottomNavigationBarItem(icon: Icon(Icons.shopify), label: 'Shop'), - BottomNavigationBarItem( - icon: Icon(Icons.book_online_outlined), label: 'Blog'), + BottomNavigationBarItem(icon: Icon(Icons.book_online_outlined), label: 'Blog'), // BottomNavigationBarItem( // icon: Icon(Icons.checkroom_outlined), label: 'Checkout'), - BottomNavigationBarItem( - icon: Icon(Icons.shopping_cart), label: 'Cart'), + BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: 'Cart'), BottomNavigationBarItem(icon: Icon(Icons.history), label: 'Orders'), BottomNavigationBarItem(icon: Icon(Icons.login), label: 'Login'), ], diff --git a/example/lib/screens/blog_tab.dart b/example/lib/screens/blog_tab.dart index 4e43baaa..966b41d8 100644 --- a/example/lib/screens/blog_tab.dart +++ b/example/lib/screens/blog_tab.dart @@ -52,9 +52,7 @@ class BlogTabState extends State { padding: const EdgeInsets.all(8), itemCount: blogs.length, itemBuilder: (_, int index) => ListTile( - title: blogs[index].title == null - ? const Text('No Title') - : Text(blogs[index].title!), + title: blogs[index].title == null ? const Text('No Title') : Text(blogs[index].title!), trailing: const Icon(Icons.arrow_forward_ios), onTap: () { if (blogs[index].articles != null) { @@ -89,8 +87,7 @@ class BlogTabState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => - PagePage(handle: pages[index].title), + builder: (context) => PagePage(handle: pages[index].title), ), ); }, diff --git a/example/lib/screens/cart_tab.dart b/example/lib/screens/cart_tab.dart index a9de46b0..3b59c46f 100644 --- a/example/lib/screens/cart_tab.dart +++ b/example/lib/screens/cart_tab.dart @@ -421,8 +421,7 @@ class _BuyerIndetityState extends State { String randomString(int n) { var text = ""; - var possible = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < n; i++) { text += possible[Random().nextInt(possible.length)]; } @@ -519,15 +518,13 @@ class _BuyerIndetityState extends State { initiallyExpanded: true, title: const Text('Delivery Address Preferences'), children: [ - if (buyerIndetity?.deliveryAddressPreferences?.isEmpty ?? - true) + if (buyerIndetity?.deliveryAddressPreferences?.isEmpty ?? true) const ListTile( title: Text('No delivery address preferences'), ), ...(buyerIndetity?.deliveryAddressPreferences ?? []).map( (mailingAddress) => ListTile( - title: Text( - '${mailingAddress?.firstName} ${mailingAddress?.lastName}'), + title: Text('${mailingAddress?.firstName} ${mailingAddress?.lastName}'), subtitle: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, diff --git a/example/lib/screens/checkout_page.dart b/example/lib/screens/checkout_page.dart index 2ee4479f..a02a6a6a 100644 --- a/example/lib/screens/checkout_page.dart +++ b/example/lib/screens/checkout_page.dart @@ -25,8 +25,7 @@ class _CheckoutPageState extends State { try { setState(() => _isLoading = true); - await shopifyAuth.signInWithEmailAndPassword( - email: kUserEmail, password: kUserPassword); + await shopifyAuth.signInWithEmailAndPassword(email: kUserEmail, password: kUserPassword); final bestSellingProducts = await shopifyStore.getNProducts( 10, @@ -97,8 +96,7 @@ class _CheckoutPageState extends State { try { setState(() => _isLoading = true); - await shopifyAuth.signInWithEmailAndPassword( - email: kUserEmail, password: kUserPassword); + await shopifyAuth.signInWithEmailAndPassword(email: kUserEmail, password: kUserPassword); final bestSellingProducts = await shopifyStore.getNProducts( 10, @@ -174,8 +172,7 @@ class _CheckoutPageState extends State { final idempotencyKey = UniqueKey().toString(); await shopifyCheckout.shippingAddressUpdate(checkout.id, address); - final tokanizedCheckout = - await shopifyCheckout.checkoutCompleteWithTokenizedPaymentV3( + final tokanizedCheckout = await shopifyCheckout.checkoutCompleteWithTokenizedPaymentV3( checkout.id, checkout: checkout, token: r'CQ32pyIRCmIEfekpX8x=', diff --git a/example/lib/screens/collection_tab.dart b/example/lib/screens/collection_tab.dart index 978d7033..6dd20637 100644 --- a/example/lib/screens/collection_tab.dart +++ b/example/lib/screens/collection_tab.dart @@ -28,8 +28,7 @@ class CollectionTabState extends State { : ListView.builder( itemCount: collections.length, itemBuilder: (_, int index) => ListTile( - onTap: () => _navigateToCollectionDetailScreen( - collections[index].id, collections[index].title), + onTap: () => _navigateToCollectionDetailScreen(collections[index].id, collections[index].title), title: Text(collections[index].title), ), ), @@ -52,21 +51,18 @@ class CollectionTabState extends State { } } - void _navigateToCollectionDetailScreen( - String collectionId, String collectionTitle) { + void _navigateToCollectionDetailScreen(String collectionId, String collectionTitle) { Navigator.push( context, MaterialPageRoute( - builder: (context) => - CollectionDetailScreen(collectionId: collectionId), + builder: (context) => CollectionDetailScreen(collectionId: collectionId), ), ); } } class CollectionDetailScreen extends StatefulWidget { - const CollectionDetailScreen({Key? key, required this.collectionId}) - : super(key: key); + const CollectionDetailScreen({Key? key, required this.collectionId}) : super(key: key); final String collectionId; @override @@ -108,8 +104,7 @@ class CollectionDetailScreenState extends State { Future _fetchProductsByCollectionId() async { try { final shopifyStore = ShopifyStore.instance; - final products = - await shopifyStore.getXProductsAfterCursorWithinCollection( + final products = await shopifyStore.getXProductsAfterCursorWithinCollection( widget.collectionId, 4, startCursor: null, @@ -132,8 +127,7 @@ class CollectionDetailScreenState extends State { Future _fetchCollectionDetail() async { try { final shopifyStore = ShopifyStore.instance; - final collectionInfo = - await shopifyStore.getCollectionById(widget.collectionId); + final collectionInfo = await shopifyStore.getCollectionById(widget.collectionId); setState(() { collection = collectionInfo; }); diff --git a/example/lib/screens/home_tab.dart b/example/lib/screens/home_tab.dart index d4a4844c..da1c21e4 100644 --- a/example/lib/screens/home_tab.dart +++ b/example/lib/screens/home_tab.dart @@ -42,8 +42,7 @@ class HomeTabState extends State { crossAxisSpacing: 8, ), itemCount: products.length, - itemBuilder: (_, int index) => - _buildProductThumbnail(products[index]), + itemBuilder: (_, int index) => _buildProductThumbnail(products[index]), ), ), ); diff --git a/example/lib/screens/product_detail_screen.dart b/example/lib/screens/product_detail_screen.dart index 48ccca2a..274fe066 100644 --- a/example/lib/screens/product_detail_screen.dart +++ b/example/lib/screens/product_detail_screen.dart @@ -4,8 +4,7 @@ import 'package:flutter/material.dart'; import 'package:shopify_flutter/shopify_flutter.dart'; class ProductDetailScreen extends StatefulWidget { - const ProductDetailScreen({Key? key, required this.product}) - : super(key: key); + const ProductDetailScreen({Key? key, required this.product}) : super(key: key); final Product product; @override diff --git a/example/lib/screens/shop_tab.dart b/example/lib/screens/shop_tab.dart index 6dcc6159..568f2d2f 100644 --- a/example/lib/screens/shop_tab.dart +++ b/example/lib/screens/shop_tab.dart @@ -81,8 +81,7 @@ query{ Future _fetchLocalizationInfo() async { try { setState(() => _isLoading = true); - final localizationInfo = - await ShopifyLocalization.instance.getLocalization(); + final localizationInfo = await ShopifyLocalization.instance.getLocalization(); if (mounted) { setState(() { localization = localizationInfo; @@ -139,25 +138,20 @@ query{ ), ListTile( title: const Text('Supported Languages'), - subtitle: Text(localization?.availableLanguages - .map((lang) => lang.name) - .toList() - .join(', ') ?? - 'N/A'), + subtitle: + Text(localization?.availableLanguages.map((lang) => lang.name).toList().join(', ') ?? 'N/A'), ), ListTile( title: const Text('Supported Currencies'), subtitle: Text(localization?.availableCountries - .map((country) => - '${country.currency.name} (${country.currency.symbol})') + .map((country) => '${country.currency.name} (${country.currency.symbol})') .toSet() .join(', ') ?? 'N/A'), ), ListTile( title: const Text('Primary Domain SSL Enabled'), - subtitle: - Text(shop?.primaryDomain?.sslEnabled.toString() ?? ''), + subtitle: Text(shop?.primaryDomain?.sslEnabled.toString() ?? ''), ), ListTile( title: const Text('Privacy Policy'), diff --git a/example/pubspec.lock b/example/pubspec.lock index 162c05f9..34aa2863 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,15 +5,15 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834 + sha256: "16e298750b6d0af7ce8a3ba7c18c69c3785d11b15ec83f6dcd0ad2a0009b3cab" url: "https://pub.dev" source: hosted - version: "72.0.0" + version: "76.0.0" _macros: dependency: transitive description: dart source: sdk - version: "0.3.2" + version: "0.3.3" alerter: dependency: "direct main" description: @@ -26,10 +26,10 @@ packages: dependency: transitive description: name: analyzer - sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139 + sha256: "1f14db053a8c23e260789e9b0980fa27f2680dd640932cae5e1137cce0e46e1e" url: "https://pub.dev" source: hosted - version: "6.7.0" + version: "6.11.0" args: dependency: transitive description: @@ -138,10 +138,10 @@ packages: dependency: transitive description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.19.0" connectivity_plus: dependency: transitive description: @@ -585,18 +585,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06" url: "https://pub.dev" source: hosted - version: "10.0.5" + version: "10.0.7" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379" url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.8" leak_tracker_testing: dependency: transitive description: @@ -625,10 +625,10 @@ packages: dependency: transitive description: name: macros - sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536" + sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656" url: "https://pub.dev" source: hosted - version: "0.1.2-main.4" + version: "0.1.3-main.0" matcher: dependency: transitive description: @@ -891,12 +891,12 @@ packages: path: ".." relative: true source: path - version: "2.3.1" + version: "2.3.3" sky_engine: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_gen: dependency: transitive description: @@ -941,10 +941,10 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.12.0" stream_channel: dependency: transitive description: @@ -957,10 +957,10 @@ packages: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" synchronized: dependency: transitive description: @@ -981,10 +981,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" url: "https://pub.dev" source: hosted - version: "0.7.2" + version: "0.7.3" typed_data: dependency: transitive description: @@ -1141,10 +1141,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b url: "https://pub.dev" source: hosted - version: "14.2.5" + version: "14.3.0" wakelock_plus: dependency: transitive description: diff --git a/lib/graphql_operations/storefront/queries/get_all_collections_optimized.dart b/lib/graphql_operations/storefront/queries/get_all_collections_optimized.dart index 25d44c60..432142db 100644 --- a/lib/graphql_operations/storefront/queries/get_all_collections_optimized.dart +++ b/lib/graphql_operations/storefront/queries/get_all_collections_optimized.dart @@ -1,6 +1,6 @@ /// Query to get all collections const String getAllCollectionsOptimizedQuery = r''' -query($cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean){ +query($metafields: [HasMetafieldsIdentifier!]!, $cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean){ collections(first: 250, after: $cursor, sortKey: $sortKey, reverse: $reverse) { pageInfo{ hasNextPage @@ -19,6 +19,23 @@ query($cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean){ id originalSrc } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } } } } diff --git a/lib/graphql_operations/storefront/queries/get_all_products_from_collection_by_id.dart b/lib/graphql_operations/storefront/queries/get_all_products_from_collection_by_id.dart index 07120cdc..a3bc4a28 100644 --- a/lib/graphql_operations/storefront/queries/get_all_products_from_collection_by_id.dart +++ b/lib/graphql_operations/storefront/queries/get_all_products_from_collection_by_id.dart @@ -1,6 +1,6 @@ /// get all related products from collection by id const String getAllProductsFromCollectionByIdQuery = r''' -query($id : ID!, $cursor : String, $sortKey: ProductCollectionSortKeys, $country: CountryCode) @inContext(country: $country){ +query($metafields: [HasMetafieldsIdentifier!]!, $id : ID!, $cursor : String, $sortKey: ProductCollectionSortKeys, $country: CountryCode) @inContext(country: $country){ node(id: $id) { ... on Collection { id @@ -22,7 +22,24 @@ query($id : ID!, $cursor : String, $sortKey: ProductCollectionSortKeys, $country id name values - } + } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } availableForSale collections(first: 250) { edges { diff --git a/lib/graphql_operations/storefront/queries/get_all_products_on_query.dart b/lib/graphql_operations/storefront/queries/get_all_products_on_query.dart index e7497a21..fa3f6b3e 100644 --- a/lib/graphql_operations/storefront/queries/get_all_products_on_query.dart +++ b/lib/graphql_operations/storefront/queries/get_all_products_on_query.dart @@ -1,6 +1,6 @@ /// Query to get all products on query const String getAllProductsOnQueryQuery = r''' -query( $cursor: String, $sortKey : ProductSortKeys, $query: String, $reverse: Boolean, $country: CountryCode) @inContext(country: $country){ +query($metafields: [HasMetafieldsIdentifier!]!, $cursor: String, $sortKey : ProductSortKeys, $query: String, $reverse: Boolean, $country: CountryCode) @inContext(country: $country){ products(query: $query, first: 250, after: $cursor, sortKey: $sortKey, reverse: $reverse) { edges { node { @@ -8,7 +8,24 @@ query( $cursor: String, $sortKey : ProductSortKeys, $query: String, $reverse: Bo id name values - } + } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } id handle availableForSale diff --git a/lib/graphql_operations/storefront/queries/get_collections.dart b/lib/graphql_operations/storefront/queries/get_collections.dart index f6bdcea3..99000678 100644 --- a/lib/graphql_operations/storefront/queries/get_collections.dart +++ b/lib/graphql_operations/storefront/queries/get_collections.dart @@ -1,6 +1,6 @@ /// Query to get all collections const String getAllCollectionsQuery = r''' -query($cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean, $country: CountryCode) @inContext(country: $country){ +query($metafields: [HasMetafieldsIdentifier!]!, $cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean, $country: CountryCode) @inContext(country: $country){ collections(first: 250, after: $cursor, sortKey: $sortKey, reverse: $reverse) { pageInfo{ hasNextPage @@ -14,6 +14,23 @@ query($cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean, $country handle id updatedAt + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } image { altText id diff --git a/lib/graphql_operations/storefront/queries/get_collections_by_ids.dart b/lib/graphql_operations/storefront/queries/get_collections_by_ids.dart index d9fcf60b..84fed8d7 100644 --- a/lib/graphql_operations/storefront/queries/get_collections_by_ids.dart +++ b/lib/graphql_operations/storefront/queries/get_collections_by_ids.dart @@ -1,9 +1,26 @@ /// Query to get collections by ids const String getCollectionsByIdsQuery = r''' -query getCollectionsByIds($ids: [ID!]!){ +query getCollectionsByIds($metafields: [HasMetafieldsIdentifier!]!, $ids: [ID!]!){ nodes(ids: $ids) { ... on Collection { id + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } handle descriptionHtml image { diff --git a/lib/graphql_operations/storefront/queries/get_featured_collections.dart b/lib/graphql_operations/storefront/queries/get_featured_collections.dart index 6b84964d..e4eb88f9 100644 --- a/lib/graphql_operations/storefront/queries/get_featured_collections.dart +++ b/lib/graphql_operations/storefront/queries/get_featured_collections.dart @@ -1,6 +1,6 @@ /// Query to get featured collection const String getFeaturedCollectionQuery = r''' -query getFeaturedCollectionQuery($query: String!, $country: CountryCode) @inContext(country: $country){ +query getFeaturedCollectionQuery($metafields: [HasMetafieldsIdentifier!]!, $query: String!, $country: CountryCode) @inContext(country: $country){ collections(query: $query, first: 1) { edges { node { @@ -10,6 +10,23 @@ query getFeaturedCollectionQuery($query: String!, $country: CountryCode) @inCon handle id updatedAt + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } image { altText id diff --git a/lib/graphql_operations/storefront/queries/get_n_products.dart b/lib/graphql_operations/storefront/queries/get_n_products.dart index 77c267ed..f0bf3492 100644 --- a/lib/graphql_operations/storefront/queries/get_n_products.dart +++ b/lib/graphql_operations/storefront/queries/get_n_products.dart @@ -1,6 +1,6 @@ /// Query to get n products const String getNProductsQuery = r''' -query($country: CountryCode, $n : Int, $sortKey : ProductSortKeys, $reverse: Boolean) @inContext(country: $country) { +query($metafields: [HasMetafieldsIdentifier!]!, $country: CountryCode, $n : Int, $sortKey : ProductSortKeys, $reverse: Boolean) @inContext(country: $country) { products(first: $n, sortKey: $sortKey, reverse: $reverse) { pageInfo { hasNextPage @@ -12,7 +12,24 @@ query($country: CountryCode, $n : Int, $sortKey : ProductSortKeys, $reverse: Boo id name values - } + } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } variants(first: 250) { edges { node { diff --git a/lib/graphql_operations/storefront/queries/get_product_by_handle.dart b/lib/graphql_operations/storefront/queries/get_product_by_handle.dart index 92e43a04..8441d9e1 100644 --- a/lib/graphql_operations/storefront/queries/get_product_by_handle.dart +++ b/lib/graphql_operations/storefront/queries/get_product_by_handle.dart @@ -1,12 +1,29 @@ /// Query to get product by handle const String getProductByHandleQuery = r''' -query getProductByHandle($country: CountryCode, $handle: String!) @inContext(country: $country) { +query getProductByHandle($metafields: [HasMetafieldsIdentifier!]!, $country: CountryCode, $handle: String!) @inContext(country: $country) { productByHandle(handle: $handle) { options(first: 50) { id name values } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } id handle collections(first: 250) { diff --git a/lib/graphql_operations/storefront/queries/get_product_recommendations.dart b/lib/graphql_operations/storefront/queries/get_product_recommendations.dart index 68877f9d..f2fffab1 100644 --- a/lib/graphql_operations/storefront/queries/get_product_recommendations.dart +++ b/lib/graphql_operations/storefront/queries/get_product_recommendations.dart @@ -1,6 +1,6 @@ /// Query to get product recommendations const String getProductRecommendationsQuery = r''' -query getProductRecommentationsQuery($id: ID!, $country: CountryCode) @inContext(country: $country){ +query getProductRecommentationsQuery($metafields: [HasMetafieldsIdentifier!]!, $id: ID!, $country: CountryCode) @inContext(country: $country){ productRecommendations(productId: $id) { availableForSale createdAt @@ -37,6 +37,23 @@ query getProductRecommentationsQuery($id: ID!, $country: CountryCode) @inContex name values } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } productType publishedAt tags diff --git a/lib/graphql_operations/storefront/queries/get_products.dart b/lib/graphql_operations/storefront/queries/get_products.dart index 807fcdbe..a94f596b 100644 --- a/lib/graphql_operations/storefront/queries/get_products.dart +++ b/lib/graphql_operations/storefront/queries/get_products.dart @@ -1,6 +1,6 @@ /// Query to get products const String getProductsQuery = r''' -query($cursor : String, $reverse: Boolean, $country: CountryCode) @inContext(country: $country){ +query($metafields: [HasMetafieldsIdentifier!]!, $cursor : String, $reverse: Boolean, $country: CountryCode) @inContext(country: $country){ products(first: 250, after: $cursor, reverse: $reverse) { pageInfo { hasNextPage @@ -13,6 +13,23 @@ query($cursor : String, $reverse: Boolean, $country: CountryCode) @inContext(co name values } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } variants(first: 250) { edges { node { diff --git a/lib/graphql_operations/storefront/queries/get_products_by_ids.dart b/lib/graphql_operations/storefront/queries/get_products_by_ids.dart index d20c3a18..1fc58dda 100644 --- a/lib/graphql_operations/storefront/queries/get_products_by_ids.dart +++ b/lib/graphql_operations/storefront/queries/get_products_by_ids.dart @@ -1,13 +1,30 @@ /// Query to get products by ids const String getProductsByIdsQuery = r''' -query($country: CountryCode, $ids : [ID!]!) @inContext(country: $country) { +query($metafields: [HasMetafieldsIdentifier!]!, $country: CountryCode, $ids : [ID!]!) @inContext(country: $country) { nodes(ids: $ids) { ... on Product { + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } options(first: 50) { id name values - } + } id handle collections(first: 250) { diff --git a/lib/graphql_operations/storefront/queries/get_x_collections_and_n_products_sorted.dart b/lib/graphql_operations/storefront/queries/get_x_collections_and_n_products_sorted.dart index f833f9e8..e1e47a03 100644 --- a/lib/graphql_operations/storefront/queries/get_x_collections_and_n_products_sorted.dart +++ b/lib/graphql_operations/storefront/queries/get_x_collections_and_n_products_sorted.dart @@ -1,6 +1,6 @@ /// Query to get x collections and n products sorted const String getXCollectionsAndNProductsSortedQuery = r''' -query($cursor: String, $sortKey: CollectionSortKeys, $sortKeyProduct: ProductCollectionSortKeys, $reverse: Boolean, $x: Int, $n: Int, $country: CountryCode) @inContext(country: $country){ +query($productMetafields: [HasMetafieldsIdentifier!]!, $collectonMetafields: [HasMetafieldsIdentifier!]!, $cursor: String, $sortKey: CollectionSortKeys, $sortKeyProduct: ProductCollectionSortKeys, $reverse: Boolean, $x: Int, $n: Int, $country: CountryCode) @inContext(country: $country){ collections(first: $x, after: $cursor, sortKey: $sortKey, reverse: $reverse) { pageInfo{ hasNextPage @@ -19,9 +19,43 @@ query($cursor: String, $sortKey: CollectionSortKeys, $sortKeyProduct: ProductCol id originalSrc } + metafields(identifiers: $collectionMetafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } products(first: $n, sortKey: $sortKeyProduct) { edges { node { + metafields(identifiers: $productMetafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } variants(first: 250) { edges { node { diff --git a/lib/graphql_operations/storefront/queries/get_x_products_after_cursor.dart b/lib/graphql_operations/storefront/queries/get_x_products_after_cursor.dart index 8cb86ca6..63013c69 100644 --- a/lib/graphql_operations/storefront/queries/get_x_products_after_cursor.dart +++ b/lib/graphql_operations/storefront/queries/get_x_products_after_cursor.dart @@ -1,6 +1,6 @@ /// Query to get x products after cursor const String getXProductsAfterCursorQuery = r''' -query($cursor : String, $x : Int, $reverse: Boolean, $sortKey: ProductSortKeys, $country: CountryCode) @inContext(country: $country){ +query($metafields: [HasMetafieldsIdentifier!]!, $cursor : String, $x : Int, $reverse: Boolean, $sortKey: ProductSortKeys, $country: CountryCode) @inContext(country: $country){ products(first: $x, after: $cursor, sortKey: $sortKey, reverse: $reverse) { pageInfo { hasNextPage @@ -12,7 +12,24 @@ query($cursor : String, $x : Int, $reverse: Boolean, $sortKey: ProductSortKeys, id name values - } + } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } variants(first: 250) { edges { node { diff --git a/lib/graphql_operations/storefront/queries/get_x_products_after_cursor_within_collection.dart b/lib/graphql_operations/storefront/queries/get_x_products_after_cursor_within_collection.dart index 0626e136..f8400afc 100644 --- a/lib/graphql_operations/storefront/queries/get_x_products_after_cursor_within_collection.dart +++ b/lib/graphql_operations/storefront/queries/get_x_products_after_cursor_within_collection.dart @@ -1,6 +1,6 @@ /// Query to get x products after cursor within collection const String getXProductsAfterCursorWithinCollectionQuery = r''' -query($id : ID!, $cursor : String, $limit : Int, $sortKey : ProductCollectionSortKeys, $reverse: Boolean, $filters: [ProductFilter!], $country: CountryCode) @inContext(country: $country){ +query($metafields: [HasMetafieldsIdentifier!]!, $id : ID!, $cursor : String, $limit : Int, $sortKey : ProductCollectionSortKeys, $reverse: Boolean, $filters: [ProductFilter!], $country: CountryCode) @inContext(country: $country){ node(id: $id) { ... on Collection { id @@ -22,7 +22,24 @@ query($id : ID!, $cursor : String, $limit : Int, $sortKey : ProductCollectionSor id name values - } + } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } availableForSale collections(first: 1) { edges { diff --git a/lib/graphql_operations/storefront/queries/get_x_products_on_query_after_cursor.dart b/lib/graphql_operations/storefront/queries/get_x_products_on_query_after_cursor.dart index 97b03b72..6cb6d4f4 100644 --- a/lib/graphql_operations/storefront/queries/get_x_products_on_query_after_cursor.dart +++ b/lib/graphql_operations/storefront/queries/get_x_products_on_query_after_cursor.dart @@ -1,14 +1,31 @@ /// Query to get x products on query after cursor const String getXProductsOnQueryAfterCursorQuery = r''' -query( $cursor: String, $limit : Int, $sortKey : ProductSortKeys, $query: String, $reverse: Boolean, $country: CountryCode) @inContext(country: $country){ +query($metafields: [HasMetafieldsIdentifier!]!, $cursor: String, $limit : Int, $sortKey : ProductSortKeys, $query: String, $reverse: Boolean, $country: CountryCode) @inContext(country: $country){ products(query: $query, first: $limit, after: $cursor, sortKey: $sortKey, reverse: $reverse) { edges { node { - options(first: 50) { - id - name - values - } + options(first: 50) { + id + name + values + } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } id handle availableForSale diff --git a/lib/graphql_operations/storefront/queries/search_product.dart b/lib/graphql_operations/storefront/queries/search_product.dart index 69ef5257..100b190c 100644 --- a/lib/graphql_operations/storefront/queries/search_product.dart +++ b/lib/graphql_operations/storefront/queries/search_product.dart @@ -1,6 +1,6 @@ /// Query search products const String getSearchedProducts = r''' -query($query: String!, $cursor : String, $limit : Int, $sortKey : SearchSortKeys, $reverse: Boolean, $filters: [ProductFilter!], $country: CountryCode) @inContext(country: $country){ +query($metafields: [HasMetafieldsIdentifier!]!, $query: String!, $cursor : String, $limit : Int, $sortKey : SearchSortKeys, $reverse: Boolean, $filters: [ProductFilter!], $country: CountryCode) @inContext(country: $country){ search(query: $query, first: $limit, sortKey: $sortKey, after: $cursor, reverse: $reverse, productFilters: $filters, types: PRODUCT){ pageInfo { hasNextPage @@ -13,7 +13,24 @@ query($query: String!, $cursor : String, $limit : Int, $sortKey : SearchSortKeys id name values - } + } + metafields(identifiers: $metafields) { + id + type + key + namespace + value + description + reference { + ... on MediaImage { + image { + originalSrc + url + id + } + } + } + } id handle collections(first: 250) { diff --git a/lib/models/json_helper.dart b/lib/models/json_helper.dart index e92d382c..21a9fc32 100644 --- a/lib/models/json_helper.dart +++ b/lib/models/json_helper.dart @@ -30,9 +30,7 @@ class JsonHelper { return []; } - return (json['edges'] as List) - .map((e) => LineItem.fromGraphJson(e)) - .toList(); + return (json['edges'] as List).map((e) => LineItem.fromGraphJson(e)).toList(); } /// returns a amount from a json object diff --git a/lib/models/src/address_autocomplete/address_details/address_details.dart b/lib/models/src/address_autocomplete/address_details/address_details.dart index d3e9f2f9..2de7442b 100644 --- a/lib/models/src/address_autocomplete/address_details/address_details.dart +++ b/lib/models/src/address_autocomplete/address_details/address_details.dart @@ -24,6 +24,5 @@ class AddressDetails with _$AddressDetails { }) = _AddressDetails; /// A factory constructor for address details - factory AddressDetails.fromJson(Map json) => - _$AddressDetailsFromJson(json); + factory AddressDetails.fromJson(Map json) => _$AddressDetailsFromJson(json); } diff --git a/lib/models/src/address_autocomplete/address_prediction/address_prediction.dart b/lib/models/src/address_autocomplete/address_prediction/address_prediction.dart index 1fddb580..768a07f6 100644 --- a/lib/models/src/address_autocomplete/address_prediction/address_prediction.dart +++ b/lib/models/src/address_autocomplete/address_prediction/address_prediction.dart @@ -16,6 +16,5 @@ class AddressPrediction with _$AddressPrediction { }) = _AddressPrediction; /// The address prediction from json - factory AddressPrediction.fromJson(Map json) => - _$AddressPredictionFromJson(json); + factory AddressPrediction.fromJson(Map json) => _$AddressPredictionFromJson(json); } diff --git a/lib/models/src/address_autocomplete/location_input/location_input.dart b/lib/models/src/address_autocomplete/location_input/location_input.dart index aebf2f28..6d50ceec 100644 --- a/lib/models/src/address_autocomplete/location_input/location_input.dart +++ b/lib/models/src/address_autocomplete/location_input/location_input.dart @@ -14,6 +14,5 @@ class LocationInput with _$LocationInput { }) = _LocationInput; /// The `LocationInput` from json - factory LocationInput.fromJson(Map json) => - _$LocationInputFromJson(json); + factory LocationInput.fromJson(Map json) => _$LocationInputFromJson(json); } diff --git a/lib/models/src/address_autocomplete/matched_substring/matched_substring.dart b/lib/models/src/address_autocomplete/matched_substring/matched_substring.dart index 2f687625..1d9b223d 100644 --- a/lib/models/src/address_autocomplete/matched_substring/matched_substring.dart +++ b/lib/models/src/address_autocomplete/matched_substring/matched_substring.dart @@ -14,6 +14,5 @@ class MatchedSubstring with _$MatchedSubstring { }) = _MatchedSubstring; /// The matched substring from json - factory MatchedSubstring.fromJson(Map json) => - _$MatchedSubstringFromJson(json); + factory MatchedSubstring.fromJson(Map json) => _$MatchedSubstringFromJson(json); } diff --git a/lib/models/src/article/article.dart b/lib/models/src/article/article.dart index ea63fe76..44045b2c 100644 --- a/lib/models/src/article/article.dart +++ b/lib/models/src/article/article.dart @@ -31,24 +31,19 @@ class Article with _$Article { }) = _Article; /// The article from json - factory Article.fromJson(Map json) => - _$ArticleFromJson(json); + factory Article.fromJson(Map json) => _$ArticleFromJson(json); /// The article from graph json factory Article.fromGraphJson(Map json) => Article( - author: AuthorV2.fromJson( - ((json['node'] ?? const {})['authorV2']) ?? const {}), - commentList: - _getCommentList((json['node'] ?? const {})['comments'] ?? const {}), + author: AuthorV2.fromJson(((json['node'] ?? const {})['authorV2']) ?? const {}), + commentList: _getCommentList((json['node'] ?? const {})['comments'] ?? const {}), content: (json['node'] ?? const {})['content'], contentHtml: (json['node'] ?? const {})['contentHtml'], excerpt: (json['node'] ?? const {})['excerpt'], excerptHtml: (json['node'] ?? const {})['excerptHtml'], handle: (json['node'] ?? const {})['handle'], id: (json['node'] ?? const {})['id'], - image: json['node']['image'] == null - ? null - : ShopifyImage.fromJson(json['node']['image']), + image: json['node']['image'] == null ? null : ShopifyImage.fromJson(json['node']['image']), publishedAt: (json['node'] ?? const {})['publishedAt'], tags: _getTagsList(json), title: (json['node'] ?? const {})['title'], @@ -57,8 +52,7 @@ class Article with _$Article { static _getCommentList(Map json) { List commentList = []; - json['edges']?.forEach((comment) => - commentList.add(Comment.fromGraphJson(comment ?? const {}))); + json['edges']?.forEach((comment) => commentList.add(Comment.fromGraphJson(comment ?? const {}))); return commentList; } diff --git a/lib/models/src/article/articles/articles.dart b/lib/models/src/article/articles/articles.dart index ae33511e..e38f369d 100644 --- a/lib/models/src/article/articles/articles.dart +++ b/lib/models/src/article/articles/articles.dart @@ -13,17 +13,14 @@ class Articles with _$Articles { factory Articles({required List
articleList}) = _Articles; /// The `Articles` from json - factory Articles.fromJson(Map json) => - _$ArticlesFromJson(json); + factory Articles.fromJson(Map json) => _$ArticlesFromJson(json); /// The `Articles` from graph json - factory Articles.fromGraphJson(Map json) => - Articles(articleList: _getArticleList(json)); + factory Articles.fromGraphJson(Map json) => Articles(articleList: _getArticleList(json)); static _getArticleList(Map json) { List
articleList = []; - json['edges']?.forEach((article) => - articleList.add(Article.fromGraphJson(article ?? const {}))); + json['edges']?.forEach((article) => articleList.add(Article.fromGraphJson(article ?? const {}))); return articleList; } } diff --git a/lib/models/src/article/author_v_2/author_v_2.dart b/lib/models/src/article/author_v_2/author_v_2.dart index 84e7952d..b104f9d4 100644 --- a/lib/models/src/article/author_v_2/author_v_2.dart +++ b/lib/models/src/article/author_v_2/author_v_2.dart @@ -8,14 +8,8 @@ part 'author_v_2.g.dart'; /// The AuthorV2 class class AuthorV2 with _$AuthorV2 { /// The AuthorV2 constructor - factory AuthorV2( - {String? bio, - String? email, - String? firstName, - String? lastName, - String? name}) = _AuthorV2; + factory AuthorV2({String? bio, String? email, String? firstName, String? lastName, String? name}) = _AuthorV2; /// The AuthorV2 from json - factory AuthorV2.fromJson(Map json) => - _$AuthorV2FromJson(json); + factory AuthorV2.fromJson(Map json) => _$AuthorV2FromJson(json); } diff --git a/lib/models/src/article/comment/comment.dart b/lib/models/src/article/comment/comment.dart index d0e4c0d7..68ce3502 100644 --- a/lib/models/src/article/comment/comment.dart +++ b/lib/models/src/article/comment/comment.dart @@ -19,8 +19,7 @@ class Comment with _$Comment { }) = _Comment; /// The Comment from json - factory Comment.fromJson(Map json) => - _$CommentFromJson(json); + factory Comment.fromJson(Map json) => _$CommentFromJson(json); /// The Comment from graph json factory Comment.fromGraphJson(Map json) => Comment( diff --git a/lib/models/src/blog/blogs/blogs.dart b/lib/models/src/blog/blogs/blogs.dart index de4beb44..2049e4a8 100644 --- a/lib/models/src/blog/blogs/blogs.dart +++ b/lib/models/src/blog/blogs/blogs.dart @@ -16,13 +16,11 @@ class Blogs with _$Blogs { factory Blogs.fromJson(Map json) => _$BlogsFromJson(json); /// The Blogs from graph json - factory Blogs.fromGraphJson(Map json) => - Blogs(blogList: _getBlogList(json)); + factory Blogs.fromGraphJson(Map json) => Blogs(blogList: _getBlogList(json)); static List _getBlogList(Map json) { List blogList = []; - json['edges'] - ?.forEach((blog) => blogList.add(Blog.fromGraphJson(blog ?? const {}))); + json['edges']?.forEach((blog) => blogList.add(Blog.fromGraphJson(blog ?? const {}))); return blogList; } } diff --git a/lib/models/src/cart/cart_buyer_identity/cart_buyer_identity.dart b/lib/models/src/cart/cart_buyer_identity/cart_buyer_identity.dart index a2bb2d45..5e867758 100644 --- a/lib/models/src/cart/cart_buyer_identity/cart_buyer_identity.dart +++ b/lib/models/src/cart/cart_buyer_identity/cart_buyer_identity.dart @@ -24,6 +24,5 @@ class CartBuyerIdentity with _$CartBuyerIdentity { }) = _CartBuyerIdentity; /// cart buyer identity from json factory - factory CartBuyerIdentity.fromJson(Map json) => - _$CartBuyerIdentityFromJson(json); + factory CartBuyerIdentity.fromJson(Map json) => _$CartBuyerIdentityFromJson(json); } diff --git a/lib/models/src/cart/cart_cost/cart_cost.dart b/lib/models/src/cart/cart_cost/cart_cost.dart index 3a30a6ea..07ba5be7 100644 --- a/lib/models/src/cart/cart_cost/cart_cost.dart +++ b/lib/models/src/cart/cart_cost/cart_cost.dart @@ -24,6 +24,5 @@ class CartCost with _$CartCost { }) = _CartCost; /// cart cost from json - factory CartCost.fromJson(Map json) => - _$CartCostFromJson(json); + factory CartCost.fromJson(Map json) => _$CartCostFromJson(json); } diff --git a/lib/models/src/cart/cart_dicount_code/cart_discount_code.dart b/lib/models/src/cart/cart_dicount_code/cart_discount_code.dart index 41a76def..e5cb2f90 100644 --- a/lib/models/src/cart/cart_dicount_code/cart_discount_code.dart +++ b/lib/models/src/cart/cart_dicount_code/cart_discount_code.dart @@ -16,6 +16,5 @@ class CartDiscountCode with _$CartDiscountCode { }) = _CartDiscountCode; /// The CartDiscountCode from json - factory CartDiscountCode.fromJson(Map json) => - _$CartDiscountCodeFromJson(json); + factory CartDiscountCode.fromJson(Map json) => _$CartDiscountCodeFromJson(json); } diff --git a/lib/models/src/cart/cart_discount_allocation/cart_discount_allocation.dart b/lib/models/src/cart/cart_discount_allocation/cart_discount_allocation.dart index 967eb05a..87e0a2f7 100644 --- a/lib/models/src/cart/cart_discount_allocation/cart_discount_allocation.dart +++ b/lib/models/src/cart/cart_discount_allocation/cart_discount_allocation.dart @@ -16,6 +16,5 @@ class CartDiscountAllocation with _$CartDiscountAllocation { }) = _CartDiscountAllocation; /// The cart discount allocation from json - factory CartDiscountAllocation.fromJson(Map json) => - _$CartDiscountAllocationFromJson(json); + factory CartDiscountAllocation.fromJson(Map json) => _$CartDiscountAllocationFromJson(json); } diff --git a/lib/models/src/cart/cart_preference/cart_delivery_coordinates_preference/cart_delivery_coordinates_preference.dart b/lib/models/src/cart/cart_preference/cart_delivery_coordinates_preference/cart_delivery_coordinates_preference.dart index 6977ddd5..84d4992c 100644 --- a/lib/models/src/cart/cart_preference/cart_delivery_coordinates_preference/cart_delivery_coordinates_preference.dart +++ b/lib/models/src/cart/cart_preference/cart_delivery_coordinates_preference/cart_delivery_coordinates_preference.dart @@ -6,8 +6,7 @@ part 'cart_delivery_coordinates_preference.g.dart'; @freezed /// The cart delivery coordinates preference -class CartDeliveryCoordinatesPreference - with _$CartDeliveryCoordinatesPreference { +class CartDeliveryCoordinatesPreference with _$CartDeliveryCoordinatesPreference { const CartDeliveryCoordinatesPreference._(); /// The cart delivery coordinates preference constructor @@ -18,7 +17,6 @@ class CartDeliveryCoordinatesPreference }) = _CartDeliveryCoordinatesPreference; /// - factory CartDeliveryCoordinatesPreference.fromJson( - Map json) => + factory CartDeliveryCoordinatesPreference.fromJson(Map json) => _$CartDeliveryCoordinatesPreferenceFromJson(json); } diff --git a/lib/models/src/cart/cart_preference/cart_delivery_preference/cart_delivery_preference.dart b/lib/models/src/cart/cart_preference/cart_delivery_preference/cart_delivery_preference.dart index 48e8b554..0b7503f8 100644 --- a/lib/models/src/cart/cart_preference/cart_delivery_preference/cart_delivery_preference.dart +++ b/lib/models/src/cart/cart_preference/cart_delivery_preference/cart_delivery_preference.dart @@ -18,6 +18,5 @@ class CartDeliveryPreference with _$CartDeliveryPreference { }) = _CartDeliveryPreference; /// The cart delivery preference from json - factory CartDeliveryPreference.fromJson(Map json) => - _$CartDeliveryPreferenceFromJson(json); + factory CartDeliveryPreference.fromJson(Map json) => _$CartDeliveryPreferenceFromJson(json); } diff --git a/lib/models/src/cart/cart_preference/cart_preference.dart b/lib/models/src/cart/cart_preference/cart_preference.dart index e761d621..1512dedc 100644 --- a/lib/models/src/cart/cart_preference/cart_preference.dart +++ b/lib/models/src/cart/cart_preference/cart_preference.dart @@ -18,6 +18,5 @@ class CartPreference with _$CartPreference { }) = _CartPreference; /// The cart preference from json - factory CartPreference.fromJson(Map json) => - _$CartPreferenceFromJson(json); + factory CartPreference.fromJson(Map json) => _$CartPreferenceFromJson(json); } diff --git a/lib/models/src/cart/customer/customer.dart b/lib/models/src/cart/customer/customer.dart index 7f917087..57723f7c 100644 --- a/lib/models/src/cart/customer/customer.dart +++ b/lib/models/src/cart/customer/customer.dart @@ -24,6 +24,5 @@ class Customer with _$Customer { }) = _Customer; /// The cart customer from json - factory Customer.fromJson(Map json) => - _$CustomerFromJson(json); + factory Customer.fromJson(Map json) => _$CustomerFromJson(json); } diff --git a/lib/models/src/cart/inputs/cart_buyer_identity_input/cart_buyer_identity_input.dart b/lib/models/src/cart/inputs/cart_buyer_identity_input/cart_buyer_identity_input.dart index e5bb3572..d6554562 100644 --- a/lib/models/src/cart/inputs/cart_buyer_identity_input/cart_buyer_identity_input.dart +++ b/lib/models/src/cart/inputs/cart_buyer_identity_input/cart_buyer_identity_input.dart @@ -21,6 +21,5 @@ class CartBuyerIdentityInput with _$CartBuyerIdentityInput { }) = _CartBuyerIdentityInput; /// the cart buyer identity input from json factory - factory CartBuyerIdentityInput.fromJson(Map json) => - _$CartBuyerIdentityInputFromJson(json); + factory CartBuyerIdentityInput.fromJson(Map json) => _$CartBuyerIdentityInputFromJson(json); } diff --git a/lib/models/src/cart/inputs/cart_input/cart_input.dart b/lib/models/src/cart/inputs/cart_input/cart_input.dart index fce04a5a..89296347 100644 --- a/lib/models/src/cart/inputs/cart_input/cart_input.dart +++ b/lib/models/src/cart/inputs/cart_input/cart_input.dart @@ -21,6 +21,5 @@ class CartInput with _$CartInput { }) = _CartInput; /// The cart input from json factory - factory CartInput.fromJson(Map json) => - _$CartInputFromJson(json); + factory CartInput.fromJson(Map json) => _$CartInputFromJson(json); } diff --git a/lib/models/src/cart/inputs/cart_line_input/cart_line_input.dart b/lib/models/src/cart/inputs/cart_line_input/cart_line_input.dart index c8630816..9d4baf6f 100644 --- a/lib/models/src/cart/inputs/cart_line_input/cart_line_input.dart +++ b/lib/models/src/cart/inputs/cart_line_input/cart_line_input.dart @@ -17,6 +17,5 @@ class CartLineInput with _$CartLineInput { }) = _CartLineInput; /// The cart line input from json factory - factory CartLineInput.fromJson(Map json) => - _$CartLineInputFromJson(json); + factory CartLineInput.fromJson(Map json) => _$CartLineInputFromJson(json); } diff --git a/lib/models/src/cart/inputs/cart_line_update_input/cart_line_update_input.dart b/lib/models/src/cart/inputs/cart_line_update_input/cart_line_update_input.dart index 65c1a4a1..1ea6f657 100644 --- a/lib/models/src/cart/inputs/cart_line_update_input/cart_line_update_input.dart +++ b/lib/models/src/cart/inputs/cart_line_update_input/cart_line_update_input.dart @@ -18,6 +18,5 @@ class CartLineUpdateInput with _$CartLineUpdateInput { }) = _CartLine; /// The cart line input from json factory - factory CartLineUpdateInput.fromJson(Map json) => - _$CartLineUpdateInputFromJson(json); + factory CartLineUpdateInput.fromJson(Map json) => _$CartLineUpdateInputFromJson(json); } diff --git a/lib/models/src/cart/inputs/delivery_address_input/delivery_address_input.dart b/lib/models/src/cart/inputs/delivery_address_input/delivery_address_input.dart index 3640e0d9..6c6f8891 100644 --- a/lib/models/src/cart/inputs/delivery_address_input/delivery_address_input.dart +++ b/lib/models/src/cart/inputs/delivery_address_input/delivery_address_input.dart @@ -23,6 +23,5 @@ class DeliveryAddressInput with _$DeliveryAddressInput { }) = _DeliveryAddressInput; /// The delivery address input from json factory - factory DeliveryAddressInput.fromJson(Map json) => - _$DeliveryAddressInputFromJson(json); + factory DeliveryAddressInput.fromJson(Map json) => _$DeliveryAddressInputFromJson(json); } diff --git a/lib/models/src/cart/inputs/mailing_address_input/mailing_address_input.dart b/lib/models/src/cart/inputs/mailing_address_input/mailing_address_input.dart index e067dce9..e82b8319 100644 --- a/lib/models/src/cart/inputs/mailing_address_input/mailing_address_input.dart +++ b/lib/models/src/cart/inputs/mailing_address_input/mailing_address_input.dart @@ -24,6 +24,5 @@ class MailingAddressInput with _$MailingAddressInput { }) = _MailingAddressInput; /// The mailing address input from json factory - factory MailingAddressInput.fromJson(Map json) => - _$MailingAddressInputFromJson(json); + factory MailingAddressInput.fromJson(Map json) => _$MailingAddressInputFromJson(json); } diff --git a/lib/models/src/cart/lines/cart_line_cost/cart_line_cost.dart b/lib/models/src/cart/lines/cart_line_cost/cart_line_cost.dart index 014d32a5..499fc371 100644 --- a/lib/models/src/cart/lines/cart_line_cost/cart_line_cost.dart +++ b/lib/models/src/cart/lines/cart_line_cost/cart_line_cost.dart @@ -19,6 +19,5 @@ class CartLineCost with _$CartLineCost { }) = _CartLineCost; /// the cart line cost from json - factory CartLineCost.fromJson(Map json) => - _$CartLineCostFromJson(json); + factory CartLineCost.fromJson(Map json) => _$CartLineCostFromJson(json); } diff --git a/lib/models/src/cart/lines/line/line.dart b/lib/models/src/cart/lines/line/line.dart index b3b436de..36223ba9 100644 --- a/lib/models/src/cart/lines/line/line.dart +++ b/lib/models/src/cart/lines/line/line.dart @@ -37,16 +37,11 @@ class Line with _$Line { return Line( id: nodeJson['id'], quantity: nodeJson['quantity'], - cost: nodeJson['cost'] != null - ? CartLineCost.fromJson(nodeJson['cost']) - : null, + cost: nodeJson['cost'] != null ? CartLineCost.fromJson(nodeJson['cost']) : null, merchandise: merchandise, variantId: merchandise?.id, - discountAllocations: (nodeJson['discountAllocations'] != null && - nodeJson['discountAllocations'] is List) - ? (nodeJson['discountAllocations'] as List) - .map((e) => CartDiscountAllocation.fromJson(e)) - .toList() + discountAllocations: (nodeJson['discountAllocations'] != null && nodeJson['discountAllocations'] is List) + ? (nodeJson['discountAllocations'] as List).map((e) => CartDiscountAllocation.fromJson(e)).toList() : null, sellingPlanAllocation: nodeJson['sellingPlanAllocation'] != null ? SellingPlanAllocation.fromJson(nodeJson['sellingPlanAllocation']) diff --git a/lib/models/src/checkout/applied_gift_cards/applied_gift_cards.dart b/lib/models/src/checkout/applied_gift_cards/applied_gift_cards.dart index 6cc57eea..09689482 100644 --- a/lib/models/src/checkout/applied_gift_cards/applied_gift_cards.dart +++ b/lib/models/src/checkout/applied_gift_cards/applied_gift_cards.dart @@ -11,12 +11,9 @@ class AppliedGiftCards with _$AppliedGiftCards { const AppliedGiftCards._(); /// The applied gift cards constructor - factory AppliedGiftCards( - {required PriceV2 amountUsedV2, - required PriceV2 balanceV2, - required String id}) = _AppliedGiftCards; + factory AppliedGiftCards({required PriceV2 amountUsedV2, required PriceV2 balanceV2, required String id}) = + _AppliedGiftCards; /// The applied gift cards from json - factory AppliedGiftCards.fromJson(Map json) => - _$AppliedGiftCardsFromJson(json); + factory AppliedGiftCards.fromJson(Map json) => _$AppliedGiftCardsFromJson(json); } diff --git a/lib/models/src/checkout/attribute/attribute.dart b/lib/models/src/checkout/attribute/attribute.dart index b096f6d9..7973bf81 100644 --- a/lib/models/src/checkout/attribute/attribute.dart +++ b/lib/models/src/checkout/attribute/attribute.dart @@ -16,6 +16,5 @@ class Attribute with _$Attribute { }) = _Attribute; /// The Attribute from json - factory Attribute.fromJson(Map json) => - _$AttributeFromJson(json); + factory Attribute.fromJson(Map json) => _$AttributeFromJson(json); } diff --git a/lib/models/src/checkout/available_shipping_rates/available_shipping_rates.dart b/lib/models/src/checkout/available_shipping_rates/available_shipping_rates.dart index a9a46ef1..695d8ec8 100644 --- a/lib/models/src/checkout/available_shipping_rates/available_shipping_rates.dart +++ b/lib/models/src/checkout/available_shipping_rates/available_shipping_rates.dart @@ -11,11 +11,9 @@ class AvailableShippingRates with _$AvailableShippingRates { const AvailableShippingRates._(); /// The available shipping rates constructor - factory AvailableShippingRates( - {required bool ready, - required List? shippingRates}) = _AvailableShippingRates; + factory AvailableShippingRates({required bool ready, required List? shippingRates}) = + _AvailableShippingRates; /// The available shipping rates from json - factory AvailableShippingRates.fromJson(Map json) => - _$AvailableShippingRatesFromJson(json); + factory AvailableShippingRates.fromJson(Map json) => _$AvailableShippingRatesFromJson(json); } diff --git a/lib/models/src/checkout/checkout.dart b/lib/models/src/checkout/checkout.dart index edd02345..71a97877 100644 --- a/lib/models/src/checkout/checkout.dart +++ b/lib/models/src/checkout/checkout.dart @@ -48,6 +48,5 @@ class Checkout with _$Checkout { }) = _Checkout; /// The checkout from json - factory Checkout.fromJson(Map json) => - _$CheckoutFromJson(json); + factory Checkout.fromJson(Map json) => _$CheckoutFromJson(json); } diff --git a/lib/models/src/checkout/line_item/line_item.dart b/lib/models/src/checkout/line_item/line_item.dart index c58cc1b3..72631376 100644 --- a/lib/models/src/checkout/line_item/line_item.dart +++ b/lib/models/src/checkout/line_item/line_item.dart @@ -30,22 +30,15 @@ class LineItem with _$LineItem { return LineItem( id: nodeJson['id'], quantity: nodeJson['quantity'], - variant: nodeJson['variant'] != null - ? ProductVariantCheckout.fromJson(nodeJson['variant']) - : null, + variant: nodeJson['variant'] != null ? ProductVariantCheckout.fromJson(nodeJson['variant']) : null, title: nodeJson['title'], discountAllocations: nodeJson['discountAllocations'] == null ? [] - : (nodeJson['discountAllocations'] as List) - .map((e) => DiscountAllocations.fromJson(e)) - .toList(), - variantId: nodeJson['variant'] != null - ? ProductVariantCheckout.fromJson(nodeJson['variant']).id - : null, + : (nodeJson['discountAllocations'] as List).map((e) => DiscountAllocations.fromJson(e)).toList(), + variantId: nodeJson['variant'] != null ? ProductVariantCheckout.fromJson(nodeJson['variant']).id : null, ); } /// The line item from json - factory LineItem.fromJson(Map json) => - _$LineItemFromJson(json); + factory LineItem.fromJson(Map json) => _$LineItemFromJson(json); } diff --git a/lib/models/src/checkout/line_items/line_items.dart b/lib/models/src/checkout/line_items/line_items.dart index 0d4c3fe3..6a0bf49b 100644 --- a/lib/models/src/checkout/line_items/line_items.dart +++ b/lib/models/src/checkout/line_items/line_items.dart @@ -12,6 +12,5 @@ class LineItems with _$LineItems { factory LineItems({required List lineItemList}) = _LineItems; /// The line items from json factory - factory LineItems.fromJson(Map json) => - _$LineItemsFromJson(json); + factory LineItems.fromJson(Map json) => _$LineItemsFromJson(json); } diff --git a/lib/models/src/checkout/mailing_address/mailing_address.dart b/lib/models/src/checkout/mailing_address/mailing_address.dart index e013d57d..afd71609 100644 --- a/lib/models/src/checkout/mailing_address/mailing_address.dart +++ b/lib/models/src/checkout/mailing_address/mailing_address.dart @@ -29,6 +29,5 @@ class MailingAddress with _$MailingAddress { }) = _MailingAddress; /// The mailing address from json - factory MailingAddress.fromJson(Map json) => - _$MailingAddressFromJson(json); + factory MailingAddress.fromJson(Map json) => _$MailingAddressFromJson(json); } diff --git a/lib/models/src/checkout/product_variant_checkout/product_variant_checkout.dart b/lib/models/src/checkout/product_variant_checkout/product_variant_checkout.dart index 351b8075..5bffa471 100644 --- a/lib/models/src/checkout/product_variant_checkout/product_variant_checkout.dart +++ b/lib/models/src/checkout/product_variant_checkout/product_variant_checkout.dart @@ -32,6 +32,5 @@ class ProductVariantCheckout with _$ProductVariantCheckout { }) = _ProductVariantCheckout; /// The product variant checkout from json - factory ProductVariantCheckout.fromJson(Map json) => - _$ProductVariantCheckoutFromJson(json); + factory ProductVariantCheckout.fromJson(Map json) => _$ProductVariantCheckoutFromJson(json); } diff --git a/lib/models/src/checkout/shipping_rates/shipping_rates.dart b/lib/models/src/checkout/shipping_rates/shipping_rates.dart index eb18f367..4ab7b184 100644 --- a/lib/models/src/checkout/shipping_rates/shipping_rates.dart +++ b/lib/models/src/checkout/shipping_rates/shipping_rates.dart @@ -11,12 +11,8 @@ class ShippingRates with _$ShippingRates { const ShippingRates._(); /// The shipping rates constructor - factory ShippingRates( - {required String handle, - required String title, - required PriceV2 priceV2}) = _ShippingRates; + factory ShippingRates({required String handle, required String title, required PriceV2 priceV2}) = _ShippingRates; /// The shipping rates from json - factory ShippingRates.fromJson(Map json) => - _$ShippingRatesFromJson(json); + factory ShippingRates.fromJson(Map json) => _$ShippingRatesFromJson(json); } diff --git a/lib/models/src/checkout/tokanized_checkout/tokanized_checkout.dart b/lib/models/src/checkout/tokanized_checkout/tokanized_checkout.dart index cfef2200..cf27b10c 100644 --- a/lib/models/src/checkout/tokanized_checkout/tokanized_checkout.dart +++ b/lib/models/src/checkout/tokanized_checkout/tokanized_checkout.dart @@ -20,13 +20,11 @@ class TokanizedCheckout with _$TokanizedCheckout { required bool ready, String? nextActionUrl, String? errorMessage, - @JsonKey(name: 'checkout', fromJson: _checkoutIdFromJson) - String? checkoutId, + @JsonKey(name: 'checkout', fromJson: _checkoutIdFromJson) String? checkoutId, }) = _TokanizedCheckout; /// The tokanized checkout from json - factory TokanizedCheckout.fromJson(Map json) => - _$TokanizedCheckoutFromJson(json); + factory TokanizedCheckout.fromJson(Map json) => _$TokanizedCheckoutFromJson(json); } String? _checkoutIdFromJson(Map json) { diff --git a/lib/models/src/collection/collection.dart b/lib/models/src/collection/collection.dart index 4803e788..ac58eaad 100644 --- a/lib/models/src/collection/collection.dart +++ b/lib/models/src/collection/collection.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:shopify_flutter/models/models.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -15,6 +17,7 @@ class Collection with _$Collection { required String title, required String id, required Products products, + required List metafields, String? cursor, String? description, String? descriptionHtml, @@ -42,14 +45,12 @@ class Collection with _$Collection { final _realProductVariants = []; for (final _variant in _product.productVariants) { if (_variant.title.toLowerCase().contains('default')) { - _realProductVariants - .add(_variant.copyWith.call(title: _product.title)); + _realProductVariants.add(_variant.copyWith.call(title: _product.title)); } else { _realProductVariants.add(_variant); } } - _realProducts - .add(_product.copyWith.call(productVariants: _realProductVariants)); + _realProducts.add(_product.copyWith.call(productVariants: _realProductVariants)); } _products = _products.copyWith.call(productList: _realProducts); @@ -61,15 +62,40 @@ class Collection with _$Collection { handle: nodeJson['handle'], id: nodeJson['id'], updatedAt: nodeJson['updatedAt'], - image: nodeJson['image'] != null - ? ShopifyImage.fromJson(nodeJson['image']) - : null, + image: nodeJson['image'] != null ? ShopifyImage.fromJson(nodeJson['image']) : null, products: _products, + metafields: _getMetafieldList(json), cursor: json['cursor'], ); } /// The collection from json - factory Collection.fromJson(Map json) => - _$CollectionFromJson(json); + factory Collection.fromJson(Map json) => _$CollectionFromJson(json); + + static List _getMetafieldList(Map json) { + try { + if (json.containsKey('node')) { + if (json['node']?['metafields'] == null) return []; + final metafields = + ((json['node']?['metafields'] ?? []) as List).map((v) => Metafield.fromGraphJson(v ?? const {})).toList(); + // remove null entries from the list + return metafields; + } else if (json['metafields'] != null) { + final metafields = + ((json['node']?['metafields'] ?? []) as List).map((v) => Metafield.fromGraphJson(v ?? const {})).toList(); + // remove null entries from the list + return metafields; + } else if (json['nodes'] != null && json['nodes'].isNotEmpty) { + final metafields = ((json['nodes'][0]?['metafields'] ?? []) as List) + .map((v) => Metafield.fromGraphJson(v ?? const {})) + .toList(); + // remove null entries from the list + return metafields; + } + return []; + } catch (e) { + log("_getMetafieldList error: $e"); + return []; + } + } } diff --git a/lib/models/src/collection/collection.freezed.dart b/lib/models/src/collection/collection.freezed.dart index f4cec197..74e13bf7 100644 --- a/lib/models/src/collection/collection.freezed.dart +++ b/lib/models/src/collection/collection.freezed.dart @@ -23,6 +23,7 @@ mixin _$Collection { String get title => throw _privateConstructorUsedError; String get id => throw _privateConstructorUsedError; Products get products => throw _privateConstructorUsedError; + List get metafields => throw _privateConstructorUsedError; String? get cursor => throw _privateConstructorUsedError; String? get description => throw _privateConstructorUsedError; String? get descriptionHtml => throw _privateConstructorUsedError; @@ -50,6 +51,7 @@ abstract class $CollectionCopyWith<$Res> { {String title, String id, Products products, + List metafields, String? cursor, String? description, String? descriptionHtml, @@ -79,6 +81,7 @@ class _$CollectionCopyWithImpl<$Res, $Val extends Collection> Object? title = null, Object? id = null, Object? products = null, + Object? metafields = null, Object? cursor = freezed, Object? description = freezed, Object? descriptionHtml = freezed, @@ -99,6 +102,10 @@ class _$CollectionCopyWithImpl<$Res, $Val extends Collection> ? _value.products : products // ignore: cast_nullable_to_non_nullable as Products, + metafields: null == metafields + ? _value.metafields + : metafields // ignore: cast_nullable_to_non_nullable + as List, cursor: freezed == cursor ? _value.cursor : cursor // ignore: cast_nullable_to_non_nullable @@ -163,6 +170,7 @@ abstract class _$$CollectionImplCopyWith<$Res> {String title, String id, Products products, + List metafields, String? cursor, String? description, String? descriptionHtml, @@ -192,6 +200,7 @@ class __$$CollectionImplCopyWithImpl<$Res> Object? title = null, Object? id = null, Object? products = null, + Object? metafields = null, Object? cursor = freezed, Object? description = freezed, Object? descriptionHtml = freezed, @@ -212,6 +221,10 @@ class __$$CollectionImplCopyWithImpl<$Res> ? _value.products : products // ignore: cast_nullable_to_non_nullable as Products, + metafields: null == metafields + ? _value._metafields + : metafields // ignore: cast_nullable_to_non_nullable + as List, cursor: freezed == cursor ? _value.cursor : cursor // ignore: cast_nullable_to_non_nullable @@ -247,13 +260,15 @@ class _$CollectionImpl extends _Collection { {required this.title, required this.id, required this.products, + required final List metafields, this.cursor, this.description, this.descriptionHtml, this.handle, this.updatedAt, this.image}) - : super._(); + : _metafields = metafields, + super._(); factory _$CollectionImpl.fromJson(Map json) => _$$CollectionImplFromJson(json); @@ -264,6 +279,14 @@ class _$CollectionImpl extends _Collection { final String id; @override final Products products; + final List _metafields; + @override + List get metafields { + if (_metafields is EqualUnmodifiableListView) return _metafields; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_metafields); + } + @override final String? cursor; @override @@ -279,7 +302,7 @@ class _$CollectionImpl extends _Collection { @override String toString() { - return 'Collection(title: $title, id: $id, products: $products, cursor: $cursor, description: $description, descriptionHtml: $descriptionHtml, handle: $handle, updatedAt: $updatedAt, image: $image)'; + return 'Collection(title: $title, id: $id, products: $products, metafields: $metafields, cursor: $cursor, description: $description, descriptionHtml: $descriptionHtml, handle: $handle, updatedAt: $updatedAt, image: $image)'; } @override @@ -291,6 +314,8 @@ class _$CollectionImpl extends _Collection { (identical(other.id, id) || other.id == id) && (identical(other.products, products) || other.products == products) && + const DeepCollectionEquality() + .equals(other._metafields, _metafields) && (identical(other.cursor, cursor) || other.cursor == cursor) && (identical(other.description, description) || other.description == description) && @@ -304,8 +329,18 @@ class _$CollectionImpl extends _Collection { @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, title, id, products, cursor, - description, descriptionHtml, handle, updatedAt, image); + int get hashCode => Object.hash( + runtimeType, + title, + id, + products, + const DeepCollectionEquality().hash(_metafields), + cursor, + description, + descriptionHtml, + handle, + updatedAt, + image); /// Create a copy of Collection /// with the given fields replaced by the non-null parameter values. @@ -328,6 +363,7 @@ abstract class _Collection extends Collection { {required final String title, required final String id, required final Products products, + required final List metafields, final String? cursor, final String? description, final String? descriptionHtml, @@ -346,6 +382,8 @@ abstract class _Collection extends Collection { @override Products get products; @override + List get metafields; + @override String? get cursor; @override String? get description; diff --git a/lib/models/src/collection/collection.g.dart b/lib/models/src/collection/collection.g.dart index 419dbb10..733dba6c 100644 --- a/lib/models/src/collection/collection.g.dart +++ b/lib/models/src/collection/collection.g.dart @@ -11,6 +11,9 @@ _$CollectionImpl _$$CollectionImplFromJson(Map json) => title: json['title'] as String, id: json['id'] as String, products: Products.fromJson(json['products'] as Map), + metafields: (json['metafields'] as List) + .map((e) => Metafield.fromJson(e as Map)) + .toList(), cursor: json['cursor'] as String?, description: json['description'] as String?, descriptionHtml: json['descriptionHtml'] as String?, @@ -26,6 +29,7 @@ Map _$$CollectionImplToJson(_$CollectionImpl instance) => 'title': instance.title, 'id': instance.id, 'products': instance.products, + 'metafields': instance.metafields, 'cursor': instance.cursor, 'description': instance.description, 'descriptionHtml': instance.descriptionHtml, diff --git a/lib/models/src/collection/collections/collections.dart b/lib/models/src/collection/collections/collections.dart index f55207db..fb05a371 100644 --- a/lib/models/src/collection/collections/collections.dart +++ b/lib/models/src/collection/collections/collections.dart @@ -10,13 +10,10 @@ part 'collections.g.dart'; /// The Collections class class Collections with _$Collections { /// The Collections constructor - factory Collections( - {required List collectionList, - required bool hasNextPage}) = _Collections; + factory Collections({required List collectionList, required bool hasNextPage}) = _Collections; /// The Collections from json - factory Collections.fromJson(Map json) => - _$CollectionsFromJson(json); + factory Collections.fromJson(Map json) => _$CollectionsFromJson(json); /// The Collections from graph json factory Collections.fromGraphJson(Map json) => Collections( @@ -26,8 +23,7 @@ class Collections with _$Collections { static List _getCollectionList(Map json) { List collectionList = []; - json['edges']?.forEach( - (e) => collectionList.add(Collection.fromGraphJson(e ?? const {}))); + json['edges']?.forEach((e) => collectionList.add(Collection.fromGraphJson(e ?? const {}))); return collectionList; } } diff --git a/lib/models/src/localization/country/country.dart b/lib/models/src/localization/country/country.dart index d6b4668f..bad7f8d1 100644 --- a/lib/models/src/localization/country/country.dart +++ b/lib/models/src/localization/country/country.dart @@ -21,6 +21,5 @@ class Country with _$Country { }) = _Country; /// The country from json factory - factory Country.fromJson(Map json) => - _$CountryFromJson(json); + factory Country.fromJson(Map json) => _$CountryFromJson(json); } diff --git a/lib/models/src/localization/currency/currency.dart b/lib/models/src/localization/currency/currency.dart index 83db9dea..6c4ba3d0 100644 --- a/lib/models/src/localization/currency/currency.dart +++ b/lib/models/src/localization/currency/currency.dart @@ -15,6 +15,5 @@ class Currency with _$Currency { }) = _Currency; /// The Currency from json - factory Currency.fromJson(Map json) => - _$CurrencyFromJson(json); + factory Currency.fromJson(Map json) => _$CurrencyFromJson(json); } diff --git a/lib/models/src/localization/language/language.dart b/lib/models/src/localization/language/language.dart index 1cd8adaf..749d8387 100644 --- a/lib/models/src/localization/language/language.dart +++ b/lib/models/src/localization/language/language.dart @@ -15,6 +15,5 @@ class Language with _$Language { }) = _Language; /// The Language from json - factory Language.fromJson(Map json) => - _$LanguageFromJson(json); + factory Language.fromJson(Map json) => _$LanguageFromJson(json); } diff --git a/lib/models/src/localization/localization.dart b/lib/models/src/localization/localization.dart index 1b4d15e4..204958d6 100644 --- a/lib/models/src/localization/localization.dart +++ b/lib/models/src/localization/localization.dart @@ -21,6 +21,5 @@ class Localization with _$Localization { }) = _Localization; /// The localization object from json - factory Localization.fromJson(Map json) => - _$LocalizationFromJson(json); + factory Localization.fromJson(Map json) => _$LocalizationFromJson(json); } diff --git a/lib/models/src/order/discount_allocations/discount_allocations.dart b/lib/models/src/order/discount_allocations/discount_allocations.dart index 71b8cb9d..da38b85a 100644 --- a/lib/models/src/order/discount_allocations/discount_allocations.dart +++ b/lib/models/src/order/discount_allocations/discount_allocations.dart @@ -11,10 +11,8 @@ class DiscountAllocations with _$DiscountAllocations { const DiscountAllocations._(); /// The discount allocations constructor - factory DiscountAllocations({required PriceV2? allocatedAmount}) = - _DiscountAllocations; + factory DiscountAllocations({required PriceV2? allocatedAmount}) = _DiscountAllocations; /// The discount allocations from json - factory DiscountAllocations.fromJson(Map json) => - _$DiscountAllocationsFromJson(json); + factory DiscountAllocations.fromJson(Map json) => _$DiscountAllocationsFromJson(json); } diff --git a/lib/models/src/order/line_item_order/line_item_order.dart b/lib/models/src/order/line_item_order/line_item_order.dart index 6aa0f9ef..f818bec5 100644 --- a/lib/models/src/order/line_item_order/line_item_order.dart +++ b/lib/models/src/order/line_item_order/line_item_order.dart @@ -27,31 +27,25 @@ class LineItemOrder with _$LineItemOrder { String? get productId => variant?.product?.id; /// The line item order from json - factory LineItemOrder.fromJson(Map json) => - _$LineItemOrderFromJson(json); + factory LineItemOrder.fromJson(Map json) => _$LineItemOrderFromJson(json); /// The line item order from json - factory LineItemOrder.fromGraphJson(Map json) => - LineItemOrder( + factory LineItemOrder.fromGraphJson(Map json) => LineItemOrder( currentQuantity: (json['node'] ?? const {})['currentQuantity'], discountAllocations: _getDiscountAllocationsList(json), - discountedTotalPrice: PriceV2.fromJson( - (json['node'] ?? const {})['discountedTotalPrice']), - originalTotalPrice: - PriceV2.fromJson((json['node'] ?? const {})['originalTotalPrice']), + discountedTotalPrice: PriceV2.fromJson((json['node'] ?? const {})['discountedTotalPrice']), + originalTotalPrice: PriceV2.fromJson((json['node'] ?? const {})['originalTotalPrice']), quantity: (json['node'] ?? const {})['quantity'], title: (json['node'] ?? const {})['title'], - variant: json['node']['variant'] == null - ? null - : ProductVariantCheckout.fromJson(json['node']['variant']), + variant: json['node']['variant'] == null ? null : ProductVariantCheckout.fromJson(json['node']['variant']), // variant: ProductVariantCheckout.fromJson( // (json['node'] ?? const {})['variant'] ?? const {}) ); static _getDiscountAllocationsList(Map json) { List discountList = []; - (json['node'] ?? const {})['discountAllocations']?.forEach( - (discount) => discountList.add(DiscountAllocations.fromJson(discount))); + (json['node'] ?? const {})['discountAllocations'] + ?.forEach((discount) => discountList.add(DiscountAllocations.fromJson(discount))); return discountList; } } diff --git a/lib/models/src/order/line_items_order/line_items_order.dart b/lib/models/src/order/line_items_order/line_items_order.dart index 0e76dc8c..4fb76a2d 100644 --- a/lib/models/src/order/line_items_order/line_items_order.dart +++ b/lib/models/src/order/line_items_order/line_items_order.dart @@ -9,12 +9,10 @@ part 'line_items_order.g.dart'; /// The line items order class LineItemsOrder with _$LineItemsOrder { /// The line items order constructor - factory LineItemsOrder({required List lineItemOrderList}) = - _LineItemsOrder; + factory LineItemsOrder({required List lineItemOrderList}) = _LineItemsOrder; /// The line items order from json factory - factory LineItemsOrder.fromJson(Map json) => - _$LineItemsOrderFromJson(json); + factory LineItemsOrder.fromJson(Map json) => _$LineItemsOrderFromJson(json); /// The line items order from graph json factory factory LineItemsOrder.fromGraphJson(Map json) => @@ -23,8 +21,7 @@ class LineItemsOrder with _$LineItemsOrder { static _getLineItemOrderList(Map json) { List lineItemListOrder = []; if (json.containsKey('edges')) { - json['edges'].forEach((lineItemOrder) => - lineItemListOrder.add(LineItemOrder.fromGraphJson(lineItemOrder))); + json['edges'].forEach((lineItemOrder) => lineItemListOrder.add(LineItemOrder.fromGraphJson(lineItemOrder))); } return lineItemListOrder; } diff --git a/lib/models/src/order/order.dart b/lib/models/src/order/order.dart index d39a15e7..aefd0ee2 100644 --- a/lib/models/src/order/order.dart +++ b/lib/models/src/order/order.dart @@ -54,18 +54,15 @@ class Order with _$Order { processedAt: json['node']['processedAt'], financialStatus: json['node']['financialStatus'], fulfillmentStatus: json['node']['fulfillmentStatus'], - shippingAddress: json['node']['shippingAddress'] == null - ? null - : ShippingAddress.fromJson(json['node']['shippingAddress']), - billingAddress: json['node']['billingAddress'] == null - ? null - : ShippingAddress.fromJson(json['node']['billingAddress']), + shippingAddress: + json['node']['shippingAddress'] == null ? null : ShippingAddress.fromJson(json['node']['shippingAddress']), + billingAddress: + json['node']['billingAddress'] == null ? null : ShippingAddress.fromJson(json['node']['billingAddress']), statusUrl: json['node']['statusUrl'], subtotalPriceV2: PriceV2.fromJson(json['node']['subtotalPriceV2']), totalPriceV2: PriceV2.fromJson(json['node']['totalPriceV2']), totalRefundedV2: PriceV2.fromJson(json['node']['totalRefundedV2']), - totalShippingPriceV2: - PriceV2.fromJson(json['node']['totalShippingPriceV2']), + totalShippingPriceV2: PriceV2.fromJson(json['node']['totalShippingPriceV2']), totalTaxV2: PriceV2.fromJson(json['node']['totalTaxV2']), cursor: json['cursor'], canceledAt: json['node']['canceledAt'], diff --git a/lib/models/src/order/orders/orders.dart b/lib/models/src/order/orders/orders.dart index c1ed9cf9..f611e977 100644 --- a/lib/models/src/order/orders/orders.dart +++ b/lib/models/src/order/orders/orders.dart @@ -10,8 +10,7 @@ part 'orders.g.dart'; /// The Orders class class Orders with _$Orders { /// The Orders constructor - factory Orders({required List orderList, required bool hasNextPage}) = - _Orders; + factory Orders({required List orderList, required bool hasNextPage}) = _Orders; /// The Orders from json factory Orders.fromJson(Map json) => _$OrdersFromJson(json); @@ -25,8 +24,7 @@ class Orders with _$Orders { static List _getOrderList(Map json) { List orderList = []; if (json.containsKey('edges')) { - json['edges'] - .forEach((e) => orderList.add(Order.fromGraphJson(e ?? const {}))); + json['edges'].forEach((e) => orderList.add(Order.fromGraphJson(e ?? const {}))); } return orderList; } diff --git a/lib/models/src/order/shipping_address/shipping_address.dart b/lib/models/src/order/shipping_address/shipping_address.dart index 6a95f3b9..a50cab39 100644 --- a/lib/models/src/order/shipping_address/shipping_address.dart +++ b/lib/models/src/order/shipping_address/shipping_address.dart @@ -28,6 +28,5 @@ class ShippingAddress with _$ShippingAddress { }) = _ShippingAddress; /// the shipping address from json - factory ShippingAddress.fromJson(Map json) => - _$ShippingAddressFromJson(json); + factory ShippingAddress.fromJson(Map json) => _$ShippingAddressFromJson(json); } diff --git a/lib/models/src/order/successful_fulfillment/successful_fulfilment_tracking_info/successful_fulfilment_tracking_info.dart b/lib/models/src/order/successful_fulfillment/successful_fulfilment_tracking_info/successful_fulfilment_tracking_info.dart index da702399..5ca824b5 100644 --- a/lib/models/src/order/successful_fulfillment/successful_fulfilment_tracking_info/successful_fulfilment_tracking_info.dart +++ b/lib/models/src/order/successful_fulfillment/successful_fulfilment_tracking_info/successful_fulfilment_tracking_info.dart @@ -6,8 +6,7 @@ part 'successful_fulfilment_tracking_info.g.dart'; @freezed /// -class SuccessfulFullfilmentTrackingInfo - with _$SuccessfulFullfilmentTrackingInfo { +class SuccessfulFullfilmentTrackingInfo with _$SuccessfulFullfilmentTrackingInfo { const SuccessfulFullfilmentTrackingInfo._(); /// the successful fullfilment tracking info @@ -26,7 +25,6 @@ class SuccessfulFullfilmentTrackingInfo ); /// the successful fullfilment tracking info from json - factory SuccessfulFullfilmentTrackingInfo.fromJson( - Map json) => + factory SuccessfulFullfilmentTrackingInfo.fromJson(Map json) => _$SuccessfulFullfilmentTrackingInfoFromJson(json); } diff --git a/lib/models/src/order/successful_fulfillment/successful_fullfilment.dart b/lib/models/src/order/successful_fulfillment/successful_fullfilment.dart index 744d8506..7ddfe0f1 100644 --- a/lib/models/src/order/successful_fulfillment/successful_fullfilment.dart +++ b/lib/models/src/order/successful_fulfillment/successful_fullfilment.dart @@ -17,15 +17,13 @@ class SuccessfulFullfilment with _$SuccessfulFullfilment { }) = _SuccessfulFullfilment; /// The successful fullfilment from graph json factory - factory SuccessfulFullfilment.fromGraphJson(Map json) => - SuccessfulFullfilment( + factory SuccessfulFullfilment.fromGraphJson(Map json) => SuccessfulFullfilment( trackingCompany: json['trackingCompany'], trackingInfo: _getTrackingInfoList(json['trackingInfo'] ?? []), ); /// The successful fullfilment from json factory - factory SuccessfulFullfilment.fromJson(Map json) => - _$SuccessfulFullfilmentFromJson(json); + factory SuccessfulFullfilment.fromJson(Map json) => _$SuccessfulFullfilmentFromJson(json); static _getTrackingInfoList(List data) { List list = []; diff --git a/lib/models/src/page/pages/pages.dart b/lib/models/src/page/pages/pages.dart index 4879d030..7231f92c 100644 --- a/lib/models/src/page/pages/pages.dart +++ b/lib/models/src/page/pages/pages.dart @@ -16,13 +16,11 @@ class Pages with _$Pages { factory Pages.fromJson(Map json) => _$PagesFromJson(json); /// - factory Pages.fromGraphJson(Map json) => - Pages(pageList: _getPageList(json)); + factory Pages.fromGraphJson(Map json) => Pages(pageList: _getPageList(json)); static List _getPageList(Map json) { List pageList = []; - json['edges'] - ?.forEach((blog) => pageList.add(Page.fromGraphJson(blog ?? const {}))); + json['edges']?.forEach((blog) => pageList.add(Page.fromGraphJson(blog ?? const {}))); return pageList; } } diff --git a/lib/models/src/product/associated_collections/associated_collections.dart b/lib/models/src/product/associated_collections/associated_collections.dart index bcd31a70..7a803126 100644 --- a/lib/models/src/product/associated_collections/associated_collections.dart +++ b/lib/models/src/product/associated_collections/associated_collections.dart @@ -20,8 +20,7 @@ class AssociatedCollections with _$AssociatedCollections { }) = _AssociatedCollections; /// The AssociatedCollections from graphjson - factory AssociatedCollections.fromGraphJson(Map json) => - AssociatedCollections( + factory AssociatedCollections.fromGraphJson(Map json) => AssociatedCollections( description: (json['node'] ?? const {})['description'], descriptionHtml: (json['node'] ?? const {})['descriptionHtml'], id: (json['node'] ?? const {})['id'], @@ -31,6 +30,5 @@ class AssociatedCollections with _$AssociatedCollections { ); /// The AssociatedCollections from json - factory AssociatedCollections.fromJson(Map json) => - _$AssociatedCollectionsFromJson(json); + factory AssociatedCollections.fromJson(Map json) => _$AssociatedCollectionsFromJson(json); } diff --git a/lib/models/src/product/metafield/metafield.dart b/lib/models/src/product/metafield/metafield.dart index 141826c9..68f1be97 100644 --- a/lib/models/src/product/metafield/metafield.dart +++ b/lib/models/src/product/metafield/metafield.dart @@ -16,20 +16,21 @@ class Metafield with _$Metafield { required String key, required String value, required String type, - @Default('') String description, + String? description, + Map? reference, }) = _Metafield; /// The Metafield from graphjson factory Metafield.fromGraphJson(Map json) => Metafield( - id: (json['node'] ?? const {})['id'], - key: (json['node'] ?? const {})['key'], - namespace: (json['node'] ?? const {})['namespace'], - type: (json['node'] ?? const {})['type'], - value: (json['node'] ?? const {})['value'], - description: (json['node'] ?? const {})['description'], + id: (json.containsKey('id') == true) ? json['id'] : '', + key: (json.containsKey('key') == true) ? json['key'] : '', + namespace: (json.containsKey('namespace') == true) ? json['namespace'] : '', + type: (json.containsKey('type') == true) ? json['type'] : '', + value: (json.containsKey('value') == true) ? json['value'] : '', + description: (json.containsKey('description') == true) ? json['description'] : null, + reference: (json.containsKey('reference') == true) ? json['reference'] : null, ); /// The Metafield from json - factory Metafield.fromJson(Map json) => - _$MetafieldFromJson(json); + factory Metafield.fromJson(Map json) => _$MetafieldFromJson(json); } diff --git a/lib/models/src/product/metafield/metafield.freezed.dart b/lib/models/src/product/metafield/metafield.freezed.dart index ed15aa92..1bf92d89 100644 --- a/lib/models/src/product/metafield/metafield.freezed.dart +++ b/lib/models/src/product/metafield/metafield.freezed.dart @@ -25,7 +25,8 @@ mixin _$Metafield { String get key => throw _privateConstructorUsedError; String get value => throw _privateConstructorUsedError; String get type => throw _privateConstructorUsedError; - String get description => throw _privateConstructorUsedError; + String? get description => throw _privateConstructorUsedError; + Map? get reference => throw _privateConstructorUsedError; /// Serializes this Metafield to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -48,7 +49,8 @@ abstract class $MetafieldCopyWith<$Res> { String key, String value, String type, - String description}); + String? description, + Map? reference}); } /// @nodoc @@ -71,7 +73,8 @@ class _$MetafieldCopyWithImpl<$Res, $Val extends Metafield> Object? key = null, Object? value = null, Object? type = null, - Object? description = null, + Object? description = freezed, + Object? reference = freezed, }) { return _then(_value.copyWith( id: null == id @@ -94,10 +97,14 @@ class _$MetafieldCopyWithImpl<$Res, $Val extends Metafield> ? _value.type : type // ignore: cast_nullable_to_non_nullable as String, - description: null == description + description: freezed == description ? _value.description : description // ignore: cast_nullable_to_non_nullable - as String, + as String?, + reference: freezed == reference + ? _value.reference + : reference // ignore: cast_nullable_to_non_nullable + as Map?, ) as $Val); } } @@ -116,7 +123,8 @@ abstract class _$$MetafieldImplCopyWith<$Res> String key, String value, String type, - String description}); + String? description, + Map? reference}); } /// @nodoc @@ -137,7 +145,8 @@ class __$$MetafieldImplCopyWithImpl<$Res> Object? key = null, Object? value = null, Object? type = null, - Object? description = null, + Object? description = freezed, + Object? reference = freezed, }) { return _then(_$MetafieldImpl( id: null == id @@ -160,10 +169,14 @@ class __$$MetafieldImplCopyWithImpl<$Res> ? _value.type : type // ignore: cast_nullable_to_non_nullable as String, - description: null == description + description: freezed == description ? _value.description : description // ignore: cast_nullable_to_non_nullable - as String, + as String?, + reference: freezed == reference + ? _value._reference + : reference // ignore: cast_nullable_to_non_nullable + as Map?, )); } } @@ -177,8 +190,10 @@ class _$MetafieldImpl extends _Metafield { required this.key, required this.value, required this.type, - this.description = ''}) - : super._(); + this.description, + final Map? reference}) + : _reference = reference, + super._(); factory _$MetafieldImpl.fromJson(Map json) => _$$MetafieldImplFromJson(json); @@ -194,12 +209,20 @@ class _$MetafieldImpl extends _Metafield { @override final String type; @override - @JsonKey() - final String description; + final String? description; + final Map? _reference; + @override + Map? get reference { + final value = _reference; + if (value == null) return null; + if (_reference is EqualUnmodifiableMapView) return _reference; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } @override String toString() { - return 'Metafield(id: $id, namespace: $namespace, key: $key, value: $value, type: $type, description: $description)'; + return 'Metafield(id: $id, namespace: $namespace, key: $key, value: $value, type: $type, description: $description, reference: $reference)'; } @override @@ -214,13 +237,15 @@ class _$MetafieldImpl extends _Metafield { (identical(other.value, value) || other.value == value) && (identical(other.type, type) || other.type == type) && (identical(other.description, description) || - other.description == description)); + other.description == description) && + const DeepCollectionEquality() + .equals(other._reference, _reference)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => - Object.hash(runtimeType, id, namespace, key, value, type, description); + int get hashCode => Object.hash(runtimeType, id, namespace, key, value, type, + description, const DeepCollectionEquality().hash(_reference)); /// Create a copy of Metafield /// with the given fields replaced by the non-null parameter values. @@ -245,7 +270,8 @@ abstract class _Metafield extends Metafield { required final String key, required final String value, required final String type, - final String description}) = _$MetafieldImpl; + final String? description, + final Map? reference}) = _$MetafieldImpl; _Metafield._() : super._(); factory _Metafield.fromJson(Map json) = @@ -262,7 +288,9 @@ abstract class _Metafield extends Metafield { @override String get type; @override - String get description; + String? get description; + @override + Map? get reference; /// Create a copy of Metafield /// with the given fields replaced by the non-null parameter values. diff --git a/lib/models/src/product/metafield/metafield.g.dart b/lib/models/src/product/metafield/metafield.g.dart index 34610d04..9b4d4c82 100644 --- a/lib/models/src/product/metafield/metafield.g.dart +++ b/lib/models/src/product/metafield/metafield.g.dart @@ -13,7 +13,8 @@ _$MetafieldImpl _$$MetafieldImplFromJson(Map json) => key: json['key'] as String, value: json['value'] as String, type: json['type'] as String, - description: json['description'] as String? ?? '', + description: json['description'] as String?, + reference: json['reference'] as Map?, ); Map _$$MetafieldImplToJson(_$MetafieldImpl instance) => @@ -24,4 +25,5 @@ Map _$$MetafieldImplToJson(_$MetafieldImpl instance) => 'value': instance.value, 'type': instance.type, 'description': instance.description, + 'reference': instance.reference, }; diff --git a/lib/models/src/product/metafield_identifier/metafield_identifier.dart b/lib/models/src/product/metafield_identifier/metafield_identifier.dart index b1997a0e..41e4be2d 100644 --- a/lib/models/src/product/metafield_identifier/metafield_identifier.dart +++ b/lib/models/src/product/metafield_identifier/metafield_identifier.dart @@ -18,6 +18,5 @@ class MetafieldIdentifier with _$MetafieldIdentifier { }) = _MetafieldIdentifier; /// Metafield identifier from json - factory MetafieldIdentifier.fromJson(Map json) => - _$MetafieldIdentifierFromJson(json); + factory MetafieldIdentifier.fromJson(Map json) => _$MetafieldIdentifierFromJson(json); } diff --git a/lib/models/src/product/price_v_2/price_v_2.dart b/lib/models/src/product/price_v_2/price_v_2.dart index 1fa802a9..0e4d8729 100644 --- a/lib/models/src/product/price_v_2/price_v_2.dart +++ b/lib/models/src/product/price_v_2/price_v_2.dart @@ -24,8 +24,7 @@ class PriceV2 with _$PriceV2 { }) = _PriceV2; /// The PriceV2 from json - factory PriceV2.fromJson(Map json) => - _$PriceV2FromJson(json); + factory PriceV2.fromJson(Map json) => _$PriceV2FromJson(json); /// The formatted price String get formattedPrice => JsonHelper.chooseRightOrderOnCurrencySymbol( @@ -35,8 +34,7 @@ class PriceV2 with _$PriceV2 { ); /// The formatted price with locale - String formattedPriceWithLocale(String? locale) => - JsonHelper.chooseRightOrderOnCurrencySymbol( + String formattedPriceWithLocale(String? locale) => JsonHelper.chooseRightOrderOnCurrencySymbol( amount, currencyCode, priceFormat: priceFormat, diff --git a/lib/models/src/product/product.dart b/lib/models/src/product/product.dart index f17d728d..8bf0002a 100644 --- a/lib/models/src/product/product.dart +++ b/lib/models/src/product/product.dart @@ -1,5 +1,6 @@ import 'dart:developer'; +import 'package:shopify_flutter/models/src/product/metafield/metafield.dart'; import 'package:shopify_flutter/models/src/product/option/option.dart'; import 'package:shopify_flutter/models/src/product/price_v_2/price_v_2.dart'; import 'package:shopify_flutter/models/src/product/product_media/product_media.dart'; @@ -35,7 +36,7 @@ class Product with _$Product { required List