appflow_flutter 0.0.6 copy "appflow_flutter: ^0.0.6" to clipboard
appflow_flutter: ^0.0.6 copied to clipboard

PlatformAndroid

An AppFlow Flutter project.

example/lib/main.dart

import 'dart:async';

import 'package:appflow_flutter/appflow_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MaterialApp(
    home: MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _appflowFlutterPlugin = AppFlowFlutter();
  String packageJson = "";
  bool isSetup = false;

  @override
  void initState() {
    super.initState();
    initPlatformState();
    setup();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion = await _appflowFlutterPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('AppFlow example app'),
        ),
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: getData(),
          ),
        ),
      ),
    );
  }

  List<Widget> getData() {
    List<Widget> data = [];
    data.add(
        TextButton(onPressed: () => {setup()}, child: const Text("setup sdk")));
    var after = [
      TextButton(
          onPressed: () async => {await _appflowFlutterPlugin.showPaywall()},
          child: const Text("showPaywall")),
      TextButton(
          onPressed: () async => {await _appflowFlutterPlugin.closePaywall()},
          child: const Text("closePaywall")),
      TextButton(
          onPressed: () async => {getSkuInfo()},
          child: const Text("getProductDetail")),
      TextButton(
          onPressed: () async => {purchasePackage()},
          child: const Text("purchasePackage")),
      TextButton(
          onPressed: () async => {getSubscriberInfo()},
          child: const Text("getSubscriberInfo")),
      TextButton(
          onPressed: () async => {sendEvent()}, child: const Text("sendEvent")),
    ];
    if (isSetup) {
      data.addAll(after);
    }
    return data;
  }

  getSubscriberInfo() async {
    try {
      var data = await _appflowFlutterPlugin.getSubscriberInfo();
      showConfirmDialog1("getSubscriberInfo success ", data.toString());
    } catch (e) {
      showConfirmDialog1("error", e.toString());
    }
  }

  getSkuInfo() async {
    try {
      var list = ["com.morning.ringtone.alarm.yearly"];
      var data = (await _appflowFlutterPlugin.getSkuDetails(skus: list));
      packageJson = data!["com.morning.ringtone.alarm.yearly"];
      showConfirmDialog1("getProductInfo success ", data.toString());
    } catch (e) {
      showConfirmDialog1("error", e.toString());
    }
  }

  upgradeProduct() async {
    try {
      var old = "com.morning.ringtone.alarm.yearly";
      var skuDetailJson = "";
      var data = await _appflowFlutterPlugin.upgradeInfo(
          old, skuDetailJson, ProrationMode.DEFERRED);
      showConfirmDialog1("success", "upgradeProduct");
    }  catch (e)  {
      showConfirmDialog1("error",e.toString());
    }
  }

  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);
      showConfirmDialog1("success", "upgradeUserInfo");
    } catch (e)  {
      showConfirmDialog1("error",e.toString());
    }
  }

  setup() async {
    try {
      await _appflowFlutterPlugin.setup(
          appUserId: "your_user_id", logEnable: true);
      setState(() {
        isSetup = true;
      });
    } catch (e) {
      showConfirmDialog1("error", e.toString());
    }
  }

  sendEvent() async {
    try {
      var map = <String, String>{};
      map["test"] = "123";
      map["test2"] = "abc";
      await _appflowFlutterPlugin.sendEvent(eventName: "test", attributes: map);
      showConfirmDialog1("success", "send event");
    } catch (e) {
      showConfirmDialog1("error", e.toString());
    }
  }

  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());
    }
  }

  Future<bool?> showConfirmDialog1(String title, String content) {
    return showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: Text(title),
          content: Text(content),
          actions: <Widget>[
            TextButton(
              child: const Text("ok"),
              onPressed: () => Navigator.of(context).pop(),
            )
          ],
        );
      },
    );
  }
}
1
likes
120
points
39
downloads

Publisher

unverified uploader

Weekly Downloads

An AppFlow Flutter project.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, freezed_annotation, json_annotation, plugin_platform_interface

More

Packages that depend on appflow_flutter