zhugeio 1.0.3 copy "zhugeio: ^1.0.3" to clipboard
zhugeio: ^1.0.3 copied to clipboard

outdated

This is the official flutter plugin for Zhugeio,with this plugin you can easily collect your app data on Android and iOS.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:zhugeio/zhugeio.dart';

import 'button.dart';

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

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

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

  TextEditingController userNameController;
  TextEditingController userKeyController;
  TextEditingController userValueController;

  TextEditingController eventNameController;
  TextEditingController key0controller;
  TextEditingController value0controller;
  TextEditingController key1controller;
  TextEditingController value1controller;


  TextEditingController priceController;
  TextEditingController productIdController;
  TextEditingController productQuantityController;
  TextEditingController typeController;


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

  // 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.
    try {
      platformVersion = await Zhugeio.platformVersion;
    } 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) {

    userNameController = new TextEditingController();
    userKeyController = new TextEditingController();
    userValueController = new TextEditingController();

    eventNameController = new TextEditingController();
    key0controller = new TextEditingController();
    value0controller = new TextEditingController();
    key1controller = new TextEditingController();
    value1controller = new TextEditingController();

    priceController = new TextEditingController();
    productIdController = new TextEditingController();
    productQuantityController = new TextEditingController();
    typeController = new TextEditingController();
    
    _buildButton(int tag, String title) {
      return new Container(
        margin: EdgeInsets.only(top: 0.0,left: 15.0),
        height: 30.0,
        width: 150.0,
        child: new MaterialButton(
          color: Colors.blue,
          textColor: Colors.white,
          child: new Text(title),
          onPressed: () {
            clickButton(tag);
          },
        ),
      );
    }

    _buildTextField(String hintText, TextEditingController _controller) {
      return new Container(
        margin: EdgeInsets.only(top: 5.0,left: 15.0,right: 15),
        height: 39.0,
//        SingleChildScrollView
        child: new TextField(
          controller: _controller,
          decoration: InputDecoration(
            contentPadding: EdgeInsets.all(5.0),
            border: OutlineInputBorder (
              borderRadius: BorderRadius.circular(4.0),
            ),
            fillColor: Colors.white70,
            filled: true,
            hintText: hintText,
          ),
        ),
      );
    }

    _buildTitle(String title) {
      return new Container(
        margin: EdgeInsets.only(top: 20.0,left: 15.0,right: 15.0),
        child: Text(
          title,
          style: TextStyle(fontWeight: FontWeight.bold),
        ),
      );
    }

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin Zhugeio app'),
        ),
        body: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              /// 用户追踪
              _buildTitle("UserID:"),

              _buildTextField("用户名", userNameController),

              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("key",userKeyController),
                  ),
                  new Expanded(
                    child: _buildTextField("value",userValueController),
                  ),
                ],
              ),
              _buildButton(0,"追踪用户"),

              /// 自定义事件追踪
              _buildTitle("自定义事件测试:"),
              _buildTextField("事件名称",eventNameController),
              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("Key0",key0controller),
                  ),
                  new Expanded(
                    child: _buildTextField("Value0",value0controller),
                  ),
                ],
              ),
              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("Key1",key1controller),
                  ),
                  new Expanded(
                    child: _buildTextField("Value1", value1controller),
                  ),
                ],
              ),
              _buildButton(1,"TrackDefault"),

              /// 收入事件追踪
              _buildTitle("收入事件测试:"),
              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("Price",priceController),
                  ),
                  new Expanded(
                    child: _buildTextField("ProductQuantity",productQuantityController),
                  ),
                ],
              ),

              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("ProductId",productIdController),
                  ),
                  new Expanded(
                    child: _buildTextField("Type",typeController),
                  ),
                ],
              ),
              _buildButton(2,"TrackRevenue"),

            ],
          ),
        )
      ),
    );
  }

  clickButton(int tag) {
    if(tag == 0) {
//      Zhugeio.identify("zhangsan", {"age":18});
      Zhugeio.identify(userNameController.text, getUserInfo());
    } else if (tag == 1) {
//      Zhugeio.track("购买", {"商品名称":"iPhone","内存":"128g"});
      Zhugeio.track(eventNameController.text, getDefaultEventsInfo());
    } else if (tag == 2) {
      Zhugeio.trackRevenue(getRevenueEventsInfo());
    }

  }

  Map getUserInfo() {
    Map userPro;
    userPro = {userKeyController.text:userValueController.text};
    print( userNameController.text + "== $userPro" );
    return userPro;
  }

  Map getDefaultEventsInfo() {
    Map defaultPro;
    defaultPro = {key0controller.text:value0controller.text, key1controller.text:value1controller.text};
    print( eventNameController.text + "== $defaultPro" );
    return defaultPro;

  }

  Map getRevenueEventsInfo() {
    Map revenuePro;
//    revenuePro.put("price",100.12);  //数值型属性不要带引号
//    revenuePro.put("productID","小米NFC手环");
//    revenuePro.put("productQuantity",2); //数值型属性不要带引号
//    revenuePro.put("revenueType","手环");
    revenuePro = {"price":priceController.text,
                  "productQuantity":productQuantityController.text,
                  "productID":productIdController.text,
                  "revenueType":typeController.text};
    print("RevenuePro == $revenuePro" );
    return revenuePro;
  }





}
0
likes
30
points
5
downloads

Publisher

unverified uploader

Weekly Downloads

This is the official flutter plugin for Zhugeio,with this plugin you can easily collect your app data on Android and iOS.

Homepage

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on zhugeio

Packages that implement zhugeio