flutter_plugin_sensors 0.0.3
flutter_plugin_sensors: ^0.0.3 copied to clipboard

Flutter Android iOS

A new Flutter plugin.

example/lib/main.dart

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_plugin_sensors/flutter_plugin_sensors.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

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: Center(
          child: ListView(
            children: <Widget>[
              new SensorsDataButton(text: "trackInstallation", onPressed: trackInstallation),
              new SensorsDataButton(text: "login", onPressed: login),
              new SensorsDataButton(text: "logout", onPressed: logout),
              new SensorsDataButton(text: "track", onPressed: track),
              new SensorsDataButton(text: "profileAppend", onPressed: profileAppend),
              new SensorsDataButton(text: "profileAppendValues", onPressed: profileAppendValues),
              new SensorsDataButton(text: "profileUnset", onPressed: profileUnset),
              new SensorsDataButton(text: "profileDelete", onPressed: profileDelete),
              new SensorsDataButton(text: "profileSet", onPressed: profileSet),
              new SensorsDataButton(text: "profileSetProperties", onPressed: profileSetProperties),
              new SensorsDataButton(text: "profileSetOnce", onPressed: profileSetOnce),
              new SensorsDataButton(text: "profileSetOnceProperties", onPressed: profileSetOnceProperties),
              new SensorsDataButton(text: "profileIncrement", onPressed: profileIncrement),
              new SensorsDataButton(text: "profileIncrementProperties", onPressed: profileIncrementProperties),
            ],
          ),
        ),
      )
    );
  }
}

// 启动安装
void trackInstallation() {
  // 方式一:只标记启动名称
  FlutterPluginSensors.trackInstallation("AppInstall");
  // 方式二:具有启动属性
  FlutterPluginSensors.trackInstallation("AppInstall", {"source": "home", "size": 30});
  // 方式三:附带回调
  FlutterPluginSensors.trackInstallation("AppInstall", {"source": "home", "size": 30}, false);
}

// 登录
void login() {
    // 方式一
    FlutterPluginSensors.login(new Random().nextInt(1000).toString());
    // 方式二:设置登录用户属性
    FlutterPluginSensors.login(new Random().nextInt(1000).toString(), {"user": "sensors", "age": 3});
}

// 注销
void logout() {
    FlutterPluginSensors.logout();
}

// track 一个事件
void track() {
    FlutterPluginSensors.track("test");
    FlutterPluginSensors.track("test", {"productName": "testProduct", "productType": "cousume"});
}

// 给一个列表类型的 Profile 增加一个元素
void profileAppend() {
  FlutterPluginSensors.profileAppend("productName", "testProduct");
}

// 给一个列表类型的 Profile 增加一个或多个元素
void profileAppendValues() {
  Set<String> set = new Set.of(["testProduct", "cousume"]);
  FlutterPluginSensors.profileAppendValues("productName", ["testProduct", "cousume", "cousume"]);
}

// 删除用户的一个 Profile
void profileUnset() {
  FlutterPluginSensors.profileUnset("productName");
}

// 删除用户的一个 Profile
void profileDelete() {
  FlutterPluginSensors.profileDelete();
}

// 设置用户的一个 Profile,如果之前存在,则覆盖,否则,新创建
void profileSet() {
  FlutterPluginSensors.profileSet("productType", "profileSet");
}

// 设置用户的一个或多个 Profile,如果之前存在,则覆盖,否则,新创建
void profileSetProperties() {
  FlutterPluginSensors.profileSetProperties({"productName": "testProduct", "productType": "profileSetProperties"});
}

// 首次设置用户的一个 Profile。 与 profileSet 接口不同的是,如果之前存在,则忽略,否则,新创建
void profileSetOnce() {
  FlutterPluginSensors.profileSet("productType", "profileSetOnce");
}

// 首次设置用户的一个或多个 Profile。 与 profileSet 接口不同的是,如果之前存在,则忽略,否则,新创建
void profileSetOnceProperties() {
  FlutterPluginSensors.profileSetProperties({"productName": "testProduct", "productType": "profileSetOnceProperties"});
}

// 给一个数值类型的 Profile 增加一个数值。只能对数值型属性进行操作,若该属性
// 未设置,则添加属性并设置默认值为 0
void profileIncrement() {
  FlutterPluginSensors.profileIncrement("productType", 123);
}

// 给一个或多个数值类型的 Profile 增加一个数值。只能对数值型属性进行操作,若该属性
// 未设置,则添加属性并设置默认值为 0
void profileIncrementProperties() {
  FlutterPluginSensors.profileIncrementProperties({"productName": 234, "productType": 456});
}

class SensorsDataButton extends StatelessWidget {
  final String text;
  final VoidCallback onPressed;

  SensorsDataButton({
    Key key,
    @required this.text,
    @required this.onPressed
  }):super(key: key);

  @override
  Widget build(BuildContext context) {
    return new RaisedButton(
      onPressed: onPressed,
      child: new Text(this.text, style: TextStyle(fontSize: 20.0)),
      textColor: Colors.white,
      disabledTextColor: Colors.red,
      color: Color(0xFF82B1FF),
      disabledColor: Colors.grey,
      highlightColor: Colors.grey,
      splashColor: Colors.green,
      colorBrightness: Brightness.light,
    );
  }

}
1
likes
75
pub points
0%
popularity

A new Flutter plugin.

Homepage

Documentation

API reference

Uploader

andoter0501@gmail.com

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_plugin_sensors