flutter_turbolink_attribution 1.0.14 copy "flutter_turbolink_attribution: ^1.0.14" to clipboard
flutter_turbolink_attribution: ^1.0.14 copied to clipboard

TurboLink's official Flutter SDK for App Attribution & Campaign.

example/lib/main.dart

import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_turbolink_attribution/flutter_turbolink_attribution.dart';
import 'package:flutter_turbolink_attribution/turbolink_custom_properties.dart';
import 'package:flutter_turbolink_attribution_example/login.dart';
// import 'package:share_plus/share_plus.dart';

final navigatorKey = GlobalKey<NavigatorState>();

void main() {
  print("main");
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  bool isDark = false;

  void _showDialog() {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      showDialog(
        context: navigatorKey.currentContext!,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text('标题'),
            content: Text('这是一个弹窗示例。'),
            actions: <Widget>[
              TextButton(
                child: Text('关闭'),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
            ],
          );
        },
      );
    });

  }

  Future<void> _share() async {
    // Share.share("Url Test:https://jeffapp.allapp.link/crpajb0gpf6gtqi95itg");
    // final shareResult = await Share.shareUri(Uri.parse("https://jeffapp.allapp.link/crpajb0gpf6gtqi95itg"));
  }

  @override
  void initState() {
    print("initState");
    super.initState();
    initTurbolinkSDK();

    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
  }

  void initTurbolinkSDK() async {
    TurbolinkSdk.enableLogger();

    TurbolinkSdk.setAppUser("jeff", "");
    TurbolinkSdk.setLang('jp');

    TurbolinkSdk.withCampaignCreateCallback((result) {
      print("TurboLinkSDK, withCampaignCreateCallback:" + result);
    });
    TurbolinkSdk.withCampaignDestroyCallback((result) {
      print("TurboLinkSDK, withCampaignDestroyCallback:" + result);
    });

    TurbolinkSdk.withLoginListenerCallback(() {
      print("TurboLinkSDK, withLoginListenerCallback:");
      // navigatorKey.currentState?.push(MaterialPageRoute(builder: (context) => LoginWidget()));
    });
    TurbolinkSdk.withRegListenerCallback(() {
      print("TurboLinkSDK, withRegListenerCallback");
      navigatorKey.currentState?.push(MaterialPageRoute(builder: (context) => LoginWidget()));
    });
    TurbolinkSdk.withEventListenerCallback((args) {
      print("TurboLinkSDK, withEventListenerCallback:${args.arguments}:${args.scheme}:${args.campaignUrl}:${args.additionalParam}");
      // TurbolinkSdk.loadUrl("https://jeffapp.c.allapp.link/c?l=crpaebp0b4mknpkano20&c=cM");
      TurbolinkSdk.closeCampaignPage();
    });
    // TurbolinkSdk.withEventCallback((args) {
    //   print(args.deviceStatus);
    // });
    TurbolinkSdk.withEventCallback((args) {
      print("TurboLinkSDK, withEventCallback:${args.linkHashId}:${args.blackBox}:${args.deviceStatus}:linkData:${args.linkData}:${args.campaignData}:${args.fromUserData['userId']}:${args.fromUserData['inviteCode']}");
    });
    TurbolinkSdk.withPointListenerCallback((args) {
      print("TurboLinkSDK, withPointListenerCallback: ${args.campaignTitle}:${args.campaignLang}:${args.campaignUrl}:${args.user}:${args.position}");
    });
    // TurbolinkSdk.withShareListenerCallback((args) {
    //   print("TurboLinkSDK, withShareListenerCallback: ${args.sharingText}: ${args.shareText}: ${args.shareLink} :${args.noInstallPrompt}: ${args.targetScheme}: ${args.campaignId}");
    // });

    TurbolinkSdk.withRedirectListenerCallback((args) {
      TurbolinkSdk.closeCampaignPage();
      print("TurboLinkSDK, withRedirectListenerCallback: ${args.campaignId}_${args.campaignTitle}_${args.campaignLang}_${args.campaignUrl}_${args.user}_${args.type}_${args.appUrl}_${args.rewardTitle}_${args.kvData.values}");
    });

    bool isInclude = TurbolinkSdk.isUrlBelongTurboLink("https://jeffapp.c.allapp.link/c?l=crbaic10b4mp5b9bi7p0&c=sO");
    print("TurboLinkSDK, ${isInclude}");
    // TurbolinkSdk.setAppUser("ben", "v1");
    TurbolinkSdk.setScreenOrientationAll();
    // TurbolinkSdk.setLaunchCampaignDelay(-1);
    // TurbolinkSdk.setNightMode(true);
    TurbolinkSdk.setInitTitle("加入中");
    TurbolinkSdk.setTitleSize(16);
    TurbolinkSdk.setIdSimpleMode();
    TurbolinkSdk.setSimpleParameterMode();
    TurbolinkSdk.setAppUserInfo("jeff", "", "", ["ok", "jeff"], "3982");
    TurbolinkSdk.setAppUser("jeff123", "ok");

    // TurbolinkSdk.loadUrl("");

    // TurbolinkSdk.withEventCallback((args) {
    //   print("TurboLinkSDK, withEventCallback:${args.linkHashId}:${args.blackBox}:${args.deviceStatus}:${args.linkData}:${args.campaignData}:${args.fromUserData['userId']}:${args.fromUserData['inviteCode']}");
    // });
    TurbolinkSdk.autoInstance('coae59progtocgji0vug', '6fbbbbe1f68712212c895522d66c241e', '6f3c7c7c24d2ba6f0d53256968e56ea4b7b4bee8');

    // TurbolinkSdk.setNightMode(true);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        appBarTheme: AppBarTheme.of(context).copyWith(
          // backgroundColor: Colors.green,
          iconTheme: IconThemeData(color: Colors.black),
          color: Colors.deepPurpleAccent,
          foregroundColor: Colors.black,
          systemOverlayStyle: SystemUiOverlayStyle(
            statusBarColor: Colors.green,
            statusBarIconBrightness: Brightness.dark,
            statusBarBrightness: Brightness.light,
          ),
          // foregroundColor: Colors.white
        ),
      ),
      navigatorKey: navigatorKey,
      debugShowCheckedModeBanner: false,
      // home: MainWidget(_platformVersion),
      home: Builder(
        builder: (context) => Scaffold(
            appBar: AppBar(
              title: const Text('Plugin example app'),
              // systemOverlayStyle: SystemUiOverlayStyle(
              //   statusBarBrightness: Brightness.dark,
              // ),
            ),
            body: Column(
              children: [
                Container(
                  child: Text('Running on: $_platformVersion\n'),
                ),
                Container(
                  child: TextButton(
                    onPressed: (){
                      print("onPressed");
                      TurbolinkSdk.loadUrl("https://jeffapp.c.allapp.link/c?l=cslj4m0gpf6nfdde71ng&c=Yo");
                      // Navigator.push(context,MaterialPageRoute(builder: (context) => LoginWidget()));
                    },
                    child: Text("活动New"),
                  ),
                ),
                TextButton(
                  onPressed: () {
                    Navigator.push(context,MaterialPageRoute(builder: (context) => LoginWidget()));
                  },
                  child: Text("Login Widget"),
                ),
                TextButton(
                  onPressed: () {
                    TurbolinkSdk.logout();
                  },
                  child: Text("Logout"),
                ),
                TextButton(
                  onPressed: () {
                    TurboLinkCustomProperties customData = TurboLinkCustomProperties()
                        .addKeyValue("name", "ben")
                        .addKeyValue("age", "22");
                    TurbolinkSdk.customEvent("pay", customData);
                  },
                  child: Text("自定义事件"),
                ),
                TextButton(
                  onPressed: () {
                    TurbolinkSdk.register("jeff", "jeff register", "https://www.turbolink.ai", ["ben", "jeff"], "33399");
                  },
                  child: Text("register"),
                ),
                TextButton(
                  onPressed: () {
                    TurbolinkSdk.codeSearch("143.42¥8QJXKXOTv2¥");
                  },
                  child: Text("codeSearch"),
                ),
                TextButton(
                  onPressed: () {
                    TurbolinkSdk.loadDelayRedirectUrl();
                  },
                  child: Text("打开延迟活动"),
                ),
                TextButton(
                  onPressed: () {
                    _showDialog();
                  },
                  child: Text("打开弹窗"),
                ),
                TextButton(
                  onPressed: () {
                    this.isDark = !this.isDark;
                    TurbolinkSdk.setNightMode(this.isDark);
                  },
                  child: Text("黑夜/白天模式"),
                ),
                TextButton(
                  onPressed: () {
                    _share();
                  }, child: Text("分享"),
                ),
              ],
            )
        ),
      )
    );
  }
}
2
likes
140
points
198
downloads

Publisher

unverified uploader

Weekly Downloads

TurboLink's official Flutter SDK for App Attribution & Campaign.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_turbolink_attribution