Skip to main content

rangers_app_log 4.0.0 copy "rangers_app_log: ^4.0.0" to clipboard
rangers_app_log: ^4.0.0 copied to clipboard

RangersAppLog的Flutter插件。支持埋点上报。

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  bool _initResult = false;
  final _rangersAppLogPlugin = RangersAppLog();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    bool initResult;
    try {
      initResult = await _rangersAppLogPlugin.init(showDebugLog: true);
    } on PlatformException catch (error) {
      debugPrint('RangersAppLog initialization failed: $error');
      initResult = false;
    }

    // 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(() {
      _initResult = initResult;
    });
    debugPrint('_initResult $_initResult');
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: SizedBox(
          width: double.infinity,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('初始化结果 : $_initResult'),
              ElevatedButton(
                onPressed: () async {
                  final result = await _rangersAppLogPlugin.onEventRegister(
                    registerWay: 'wechat',
                  );
                  debugPrint('$result');
                },
                child: const Text('注册事件'),
              ),
              ElevatedButton(
                onPressed: () async {
                  ///onEventPurchase("gift","flower", "008",1, "wechat","¥", true, 1);/
                  final result = await _rangersAppLogPlugin
                      .onEventPurchaseonEventPurchase(
                        commodityType: 'gift',
                        tradeName: 'flower',
                        productId: '008',
                        productCount: 13,
                        payWay: 'wechat',
                        payCurrency: '¥',
                        paySuccess: true,
                        payMoney: 100,
                      );
                  debugPrint('$result');
                },
                child: const Text('购买事件'),
              ),
              ElevatedButton(
                onPressed: () async {
                  ///onEventPurchase("gift","flower", "008",1, "wechat","¥", true, 1);/
                  final result = await _rangersAppLogPlugin.onClick(
                    eventName: 'click',
                    params: {'productId': 'abc123123'},
                  );
                  debugPrint('$result');
                },
                child: const Text('点击'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
135
points
49
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

RangersAppLog的Flutter插件。支持埋点上报。

Repository

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on rangers_app_log

Packages that implement rangers_app_log