{
    "componentChunkName": "component---node-modules-rocketseat-gatsby-theme-docs-core-src-templates-docs-query-js",
    "path": "/docs/flutter/show-subscription-offer/",
    "result": {"data":{"mdx":{"id":"bb81a0a7-6fd2-58f2-90fc-273d5db1ebe2","excerpt":"Please read  How to initialize the plugin  before you start with this part. If the user has no active subscriptions, you would want to fetch all available…","fields":{"slug":"/docs/flutter/show-subscription-offer/"},"frontmatter":{"title":"Show your Subscription Offer","description":"Learn how to fetch Subscriptions and get all subscription you want to offer to the user with the Flutter LinkFive Plugin","image":null,"disableTableOfContents":null},"body":"var _excluded = [\"components\"];\nfunction _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n/* @jsxRuntime classic */\n/* @jsx mdx */\n\nvar _frontmatter = {\n  \"title\": \"Show your Subscription Offer\",\n  \"description\": \"Learn how to fetch Subscriptions and get all subscription you want to offer to the user with the Flutter LinkFive Plugin\"\n};\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n    props = _objectWithoutProperties(_ref, _excluded);\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"blockquote\", null, mdx(\"p\", {\n    parentName: \"blockquote\"\n  }, \"Please read \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/docs/flutter/initializing/\"\n  }, \"How to initialize the plugin\"), \" before you start with this part.\")), mdx(\"p\", null, \"If the user has no active subscriptions, you would want to fetch all available subscriptions you configured\\nin the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/docs/dashboard/subscription-playout/\"\n  }, \"\\u201CPlayout section\\u201C of LinkFive\"), \" - if you did not configured it yet, no worries,\\nall connected subscriptions will be fetched.\"), mdx(\"h2\", {\n    \"id\": \"fetch-your-subscriptions-offer\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#fetch-your-subscriptions-offer\",\n    \"aria-label\": \"fetch your subscriptions offer permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Fetch your Subscriptions Offer\"), mdx(\"p\", null, \"To fetch all available subscriptions, call fetchProducts().\\nIt's usually enough to call it once when the user enters the paywall or even once after every app start if the user has no active subscriptions yet.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"LinkFivePurchases.fetchProducts();\\n\")), mdx(\"p\", null, \"This will connect to LinkFive and fetch all available subscriptions you configured with the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/docs/dashboard/subscription-playout/\"\n  }, \"\\u201CSubscription Playout\\u201C\"), \".\\nIf you created a subscription playout filter, then it will automatically fetch the filtered subscriptions to the user.\"), mdx(\"p\", null, \"The subscriptions will then be passed to the \\u201CSubscriptionData\\u201C stream.\"), mdx(\"h3\", {\n    \"id\": \"get-subscriptions-stream\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#get-subscriptions-stream\",\n    \"aria-label\": \"get subscriptions stream permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Get Subscriptions Stream\"), mdx(\"p\", null, \"You will get the stream by listening on the SubscriptionData\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"LinkFivePurchases.products\\n    .listen(_productsUpdate)\\n//...\\n\\n  void _productsUpdate(LinkFiveProducts data) {\\n    // access LinkFiveProducts data\\n  }\\n\")), mdx(\"p\", null, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"LinkFiveProducts\"), \" includes a list of ProductDetails and attributes. You can use the ProductDetails to show the price, the duration and everything related to it.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"// available variables of LinkFiveProducts\\nList<LinkFiveProductDetails> productDetailList;\\nString? attributes;\\n\")), mdx(\"ul\", null, mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"p\", {\n    parentName: \"li\"\n  }, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"LinkFiveProductDetails\"), \": id, title, price, description, duration, rawPrice & currencyCode\")), mdx(\"li\", {\n    parentName: \"ul\"\n  }, mdx(\"p\", {\n    parentName: \"li\"\n  }, mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"attributes\"), \": Data defined in \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/docs/dashboard/subscription-playout/\"\n  }, \"\\u201CSubscription Playout\\u201C\"), \". You can pass any data you like to the app with the attributes. Attributes are \", mdx(\"strong\", {\n    parentName: \"p\"\n  }, \"Base64 encoded\"), \". Please decode first.\"))), mdx(\"p\", null, \"As an example, you can use the map method to build a button for each of your subscriptions\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"productDetailList.map(\\n    (data) => SubscriptionButton(linkFiveProductDetails: data)\\n)\\n\")), mdx(\"p\", null, \"And you can access the price by accessing the productDetails\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"productDetailList ... productDetails.price\\n\")), mdx(\"h3\", {\n    \"id\": \"provider-example\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#provider-example\",\n    \"aria-label\": \"provider example permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Provider Example\"), mdx(\"p\", null, \"A simple provider example on how to listen on active subscriptions and on subscriptionData:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"class LinkFiveProvider extends ChangeNotifier {\\n  final LinkFivePurchasesMain linkFivePurchases = LinkFivePurchasesMain();\\n  LinkFiveProducts? products;\\n  LinkFiveActiveProducts? activeProducts;\\n\\n  List<StreamSubscription> _streams = [];\\n\\n  List<LinkFivePlan> get activePlanList => activeProducts?.planList ?? [];\\n  bool get hasActiveProduct => activeProducts != null && activeProducts!.planList.isNotEmpty;\\n\\n  LinkFiveProvider(String apiKey) {\\n    linkFivePurchases.init(apiKey);\\n    _streams.add(linkFivePurchases.products.listen(_productsUpdate));\\n    _streams.add(linkFivePurchases.activeProducts.listen(_activeProductsUpdate));\\n  }\\n\\n  void _productsUpdate(LinkFiveProducts data) {\\n    products = data;\\n    notifyListeners();\\n  }\\n\\n  void _activeProductsUpdate(LinkFiveActiveProducts data) {\\n    activeProducts = data;\\n    notifyListeners();\\n  }\\n\\n  Future<LinkFiveProducts?> fetchProducts() {\\n    return LinkFivePurchases.fetchProducts();\\n  }\\n\\n  restoreSubscriptions() {\\n    return LinkFivePurchases.restore();\\n  }\\n\\n  Future<bool> purchase(ProductDetails productDetail) async {\\n    return LinkFivePurchases.purchase(productDetail);\\n  }\\n\\n  @override\\n  void dispose() async {\\n    for (var element in _streams) {\\n      await element.cancel();\\n    }\\n    _streams = [];\\n    super.dispose();\\n  }\\n}\\n\")), mdx(\"h3\", {\n    \"id\": \"streambuilder-example\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#streambuilder-example\",\n    \"aria-label\": \"streambuilder example permalink\",\n    \"className\": \"anchor before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"StreamBuilder Example\"), mdx(\"p\", null, \"If you want to use a simple StreamBuilder, you can just pass the stream and wait for the snapshot to arrive.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-dart\"\n  }, \"  Container(\\n    child: StreamBuilder<LinkFiveProducts>(\\n      stream: LinkFivePurchases.products,\\n      builder: (context, snapshot) {\\n        if (snapshot.hasData) {\\n          var subscriptionData = snapshot.data;\\n          if (subscriptionData != null) {\\n            return Column(\\n              children: [\\n                Row(\\n                  children: buildSubscriptionButtons(subscriptionData),\\n                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,\\n                )\\n              ],\\n            );\\n          }\\n        }\\n        return Center(child: Text('Loading...'));\\n      },\\n  ));\\n\")), mdx(\"blockquote\", null, mdx(\"p\", {\n    parentName: \"blockquote\"\n  }, \"Next: \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/docs/flutter/make-a-purchase/\"\n  }, \"Make a purchase\"))));\n}\n;\nMDXContent.isMDXComponent = true;","headings":[{"depth":2,"value":"Fetch your Subscriptions Offer"},{"depth":3,"value":"Get Subscriptions Stream"},{"depth":3,"value":"Provider Example"},{"depth":3,"value":"StreamBuilder Example"}]}},"pageContext":{"slug":"/docs/flutter/show-subscription-offer/","next":{"label":"Introduction","link":"/docs/docs/"},"repositoryEditUrl":"","repositoryProvider":""}},
    "staticQueryHashes": ["1954253342","2328931024","2501019404","973074209"]}