td_strategy 1.0.0 copy "td_strategy: ^1.0.0" to clipboard
td_strategy: ^1.0.0 copied to clipboard

Official Thinking Strategy Flutter plugin.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:td_strategy/strategy.dart';
import 'package:thinking_analytics/td_analytics.dart';
import 'package:td_remote_config/remote_config.dart';

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

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

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

const appId = "a3a3493ebff5474a98e9f98c56edd54f";
const serverUrl = "http://10.82.3.185:8991";

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: CustomScrollView(shrinkWrap: true, slivers: <Widget>[
          SliverPadding(
            padding: const EdgeInsets.all(2.0),
            sliver: SliverList(
              delegate: SliverChildListDelegate(
                [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                          child: OutlinedButton(
                              child: const Text(
                                '初始化',
                                style: TextStyle(fontSize: 14),
                              ),
                              onPressed: () => {initSDK()})),
                      Expanded(
                          child: OutlinedButton(
                              child: const Text(
                                '手动拉取任务',
                                style: TextStyle(fontSize: 12),
                              ),
                              onPressed: () => {fetch()})),
                      Expanded(
                          child: OutlinedButton(
                              child: const Text(
                                '发送事件',
                                style: TextStyle(fontSize: 14),
                              ),
                              onPressed: () => {trackEvent()})),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ]),
      ),
    );
  }

  void initSDK() async {
    TDAnalytics.enableLog(true);
    TDRemoteConfig.enableLog(true);
    TDStrategy.enableLog(true);
    TDAnalytics.init(appId, serverUrl);
    TDRemoteConfigSettings settings = TDRemoteConfigSettings();
    settings.appId = appId;
    settings.serverUrl = serverUrl;
    TDRemoteConfig.initWithConfig(settings);
    TDStrategySettings strategySettings = TDStrategySettings();
    strategySettings.appId = appId;
    strategySettings.serverUrl = serverUrl;
    strategySettings.mode = TDStrategyMode.NORMAL;
    TDStrategy.initWithConfig(strategySettings);
    TDAnalytics.login("aaaa");
    TDStrategy.setTriggerListener((statusData) {
      print("========");
      print(statusData);
    });
  }

  void fetch() {
    TDStrategy.fetch();
  }

  void trackEvent() {
    TDAnalytics.track("beginner_guide");
  }
}
0
likes
135
points
112
downloads

Publisher

unverified uploader

Weekly Downloads

Official Thinking Strategy Flutter plugin.

Homepage

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, td_remote_config

More

Packages that depend on td_strategy

Packages that implement td_strategy