Flutter set up instructions
Instructions For Installing Appflow SDK For Flutter
Notices
Our plugin relies on Appflow SDK, so before you use the plugin, please go to Appflow official website to install and configure Appflow SDK for Android and IOS.
Requirements
Minimum target: Android 21+
Installation
To use this plugin, add appflow_flutter as a dependency in your pubspec.yaml file (and run an implicit dart pub get):
dependencies:
appflow_flutter: ^0.0.4
Alternatively run this command:
flutter pub add appflow_flutter
Import Appflow
You should now be able to import appflow_flutter
import 'package:appflow_flutter/appflow_flutter.dart';
**Initialize **
Add the following to your App
@override
void initState() {
super.initState();
AppFlowFlutter().setup();
}
Set user id (optional) You can set the user id in the following way
@override
void initState() {
super.initState();
AppFlowFlutter().setup(appUserId: "your_user_id");
}
Enable SDK log (optional) You can enable SDK log output before initializing the SDK
@override
void initState() {
super.initState();
AppFlowFlutter().setup(appUserId: "your_user_id",logEnable: true);
}
Events
If you want to receive more events than usual: You can send statistics events to Appflow backend in the following ways
AppFlowFlutter().sendEvent({String? eventName, Map<String, String>? attributes});
Example
sendEvent() async {
try {
var map = <String,String>{};
map["test"] = "123";
map["test2"] = "abc";
await _appflowFlutterPlugin.sendEvent(eventName: "test",attributes: map);
} catch (e) {
}
}
Purchases
This part of SDK is important for subscriptions information Ready to work a、Configure product information in Google Play
b、Add product information in dash.appflow.ai
Displaying Products To fetch the products, you have to call method:
AppFlowFlutter().getSkuDetails({List<String>? skus});
Example
getSkuInfo() async {
try{
var list = ["yearly_v1"];
var data = (await _appflowFlutterPlugin.getSkuDetails(skus: list));
packageJson = data!["yearly_v1"];
}catch(e){
}
}
Making Purchases
Making Purchases, you have to call method:
AppFlowFlutter().purchasePackage(String skuDetail);
Example
purchasePackage() async {
if (packageJson.isEmpty) {
showConfirmDialog1("error", "please invoke getProductDetail method before invoke purchasePackage");
return;
}
try {
var data = await _appflowFlutterPlugin.purchasePackage(packageJson);
print(data);
} catch (e, stack) {
showConfirmDialog1("error", e.toString());
}
}
Subscription Status
Get the subscription status of a product, you have to call method:
AppFlowFlutter().getSubscriberInfo();
Example
getSubscriberInfo() async {
try{
var data = await _appflowFlutterPlugin.getSubscriberInfo();
}catch(e){
showConfirmDialog1("error", e.toString());
}
}
Upgrade/Downgrade product
To upgrade/downgrade a product, you have to call method:
AppFlowFlutter().upgradeInfo(
String oldSku, String skuDetail, int? prorationMode);
Example
upgradeProduct() async {
try {
var old = "yearly_v1";
var skuDetailJson = "";
var data = await _appflowFlutterPlugin.upgradeInfo(
old, skuDetailJson, ProrationMode.DEFERRED);
} on PlatformException {}
}
User info
You can send user information to Appflow backend in the following ways
AppFlowFlutter().uploadUserInfo(
{String? userName,
String? phone,
int? age,
String? email,
GenderType? gender,
Map<String, dynamic>? attribute});
Example
upgradeUserInfo() async {
try {
var map = <String, String>{};
map["test"] = "123";
map["test2"] = "abc";
var data = await _appflowFlutterPlugin.uploadUserInfo(
userName: "appflow",
phone: "1233",
age: 11,
email: "1234@gmail.com",
gender: GenderType.female,
attribute: map);
} on PlatformException {}
}
Libraries
- appflow_flutter
- appflow_flutter_method_channel
- appflow_flutter_platform_interface
- generated/json/base/json_convert_content
- generated/json/base/json_field
- generated/json/entitlement_entity.g
- generated/json/sku_details_entity.g
- generated/json/test_entity.g
- model/entitlement_entity
- model/sku_details_entity
- model/test_entity
- object_wrappers