Skip to content

Commit 1d27bc7

Browse files
authored
Add Flutter VC Docs (#1013)
1 parent fcd356c commit 1d27bc7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// NOTE: Virtual currencies are not yet supported in Flutter web and
2+
// are only available for Flutter on iOS and Android.
3+
4+
// Fetch virtual currencies
5+
try {
6+
final virtualCurrencies = await Purchases.getVirtualCurrencies();
7+
// TODO: Handle virtual currencies
8+
} catch (error) {
9+
// TODO: Handle error
10+
}
11+
12+
// Get the details of a specific virtual currency
13+
final virtualCurrency = virtualCurrencies.all[<virtual_currency_code>];
14+
final balance = virtualCurrency?.balance;
15+
final name = virtualCurrency?.name;
16+
final code = virtualCurrency?.code;
17+
18+
// Keep in mind that serverDescription may be null if no description was provided
19+
// in the RevenueCat dashboard
20+
final serverDescription = virtualCurrency?.serverDescription;
21+
22+
// Iterate through all virtual currencies
23+
virtualCurrencies.all.forEach((virtualCurrencyCode, virtualCurrency) {
24+
print('$virtualCurrencyCode: ${virtualCurrency.balance}');
25+
});

docs/offerings/virtual-currency.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import fetchVCBalancesSwift from "@site/code_blocks/virtual-currency/vc-balance-
9696
import fetchVCBalancesKotlin from "@site/code_blocks/virtual-currency/vc-balance-sdk-android.kt?raw";
9797
import fetchVCBalancesJava from "@site/code_blocks/virtual-currency/vc-balance-sdk-android.java?raw";
9898
import fetchVCBalancesReactNative from "@site/code_blocks/virtual-currency/vc-balance-sdk-react-native.ts?raw";
99+
import fetchVCBalancesFlutter from "@site/code_blocks/virtual-currency/vc-balance-sdk-flutter.dart?raw";
99100

100101
Fetching virtual currency balances is supported in the following SDK versions:
101102

@@ -104,6 +105,7 @@ Fetching virtual currency balances is supported in the following SDK versions:
104105
| iOS SDK | 5.32.0+ |
105106
| Android SDK | 9.1.0+ |
106107
| React Native SDK | 9.1.0+ |
108+
| Flutter SDK | 9.1.0+ |
107109

108110
You can use the `virtualCurrencies()` function to retrieve a customer's balance. The function returns a `VirtualCurrencies` object, which includes the customer's balances along with each virtual currency's metadata.
109111

@@ -129,6 +131,11 @@ You can use the `virtualCurrencies()` function to retrieve a customer's balance.
129131
title: "React Native",
130132
content: fetchVCBalancesReactNative,
131133
},
134+
{
135+
type: "flutter",
136+
title: "Flutter",
137+
content: fetchVCBalancesFlutter,
138+
},
132139
]}
133140
/>
134141

0 commit comments

Comments
 (0)