tiktok_business_sdk 0.0.1 copy "tiktok_business_sdk: ^0.0.1" to clipboard
tiktok_business_sdk: ^0.0.1 copied to clipboard

A Flutter plugin that integrates TikTok Business SDK 1.5.0

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:tiktok_business_sdk/tiktok_business_sdk.dart';
import 'package:tiktok_business_sdk/tiktok_business_sdk_platform_interface.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await dotenv.load();
  runApp(const MyApp());
}

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _tiktokBusinessSdkPlugin = TiktokBusinessSdk();

  @override
  void initState() {
    super.initState();
    initPlatformState();
    // _tiktokBusinessSdkPlugin.initTiktokBusinessSdk(
    //   accessToken: dotenv.env['accessToken'] ?? '',
    //   appId: dotenv.env['appId'] ?? '',
    //   ttAppId: dotenv.env['ttAppId'] ?? '',
    //   openDebug: true,
    //   enableAutoIapTrack: true,
    // );
  }

  // 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 _tiktokBusinessSdkPlugin.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('Plugin example app')),
        body: Container(
          width: double.infinity,
          decoration: BoxDecoration(
            border: Border.all(color: Colors.red),
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            children: [
              ElevatedButton(
                onPressed: () {
                  _tiktokBusinessSdkPlugin.initTiktokBusinessSdk(
                    accessToken: dotenv.env['accessToken'] ?? '',
                    appId: dotenv.env['appId'] ?? '',
                    ttAppId: dotenv.env['ttAppId'] ?? '',
                    openDebug: true,
                    enableAutoIapTrack: true,
                  );
                },
                child: Text('Init Tiktok Business SDK'),
              ),
              ElevatedButton(
                onPressed: () {
                  _tiktokBusinessSdkPlugin.setIdentify(
                    externalId: '1234567890',
                    externalUserName: 'John Doe',
                    phoneNumber: '1234567890',
                    email: '[email protected]',
                  );
                },
                child: Text('Set Identify'),
              ),
              ElevatedButton(
                onPressed: () {
                  _tiktokBusinessSdkPlugin.logout();
                },
                child: Text('Logout'),
              ),
              ElevatedButton(
                onPressed: () {
                  _tiktokBusinessSdkPlugin.trackTTEvent(
                    event: EventName.AchieveLevel,
                  );
                },
                child: Text('Track TT Event'),
              ),
              Text('Platform Version: $_platformVersion'),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
45
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin that integrates TikTok Business SDK 1.5.0

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on tiktok_business_sdk

Packages that implement tiktok_business_sdk