flutter_growingio_touch 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 46

flutter_growingio_touch #

The Flutter plugin for GrowingIO Touch.

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

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

import 'package:flutter_growingio_touch/flutter_growingio_touch.dart';
import 'package:flutter_growingio_track/flutter_growingio_track.dart';

void main() {
  Widget app = MyApp();
  runApp(app);
  openEventPopup();
}

void openEventPopup() async {
  if (!await GrowingTouch.eventPopupEnable) {
    GrowingTouch.eventPopupListener = EventPopupListener(
      onLoadSuccess: (eventId, eventType) => print('onLoadSuccess: eventId = ' + eventId + ', eventType = ' + eventType),
      onLoadFailed: (eventId, eventType, errorCode, description) => print('onLoadFailed: eventId = ' + eventId + ', eventType = ' + eventType + ', errorCode = ' + errorCode.toString() + ', description = ' + description),
      onCancel: (eventId, eventType) => print('onCancel: eventId = ' + eventId + ', eventType = ' + eventType),
      onClicked: (eventId, eventType, openUrl) => print('onClicked: eventId = ' + eventId + ', eventType = ' + eventType + ', openUrl = ' + openUrl),
      onTimeout: (eventId, eventType) => print('onTimeout: eventId = ' + eventId + ', eventType = ' + eventType),
    );
    GrowingTouch.enableEventPopupAndGenerateAppOpenEvent();
  }
}

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('GTouch Flutter'),
        ),
        body: _HomePage(),
      ),
    );
  }
}

class _HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _HomePageState();
}

class _HomePageState extends State<_HomePage> {
  bool _popupEnable = true;

  @override
  void initState() {
    super.initState();
//    initPopupEnable();
  }

  Future<void> initPopupEnable() async {
    bool state = await GrowingTouch.eventPopupEnable;
    print("eventPopupEnable is " + state.toString());
    setState(() {
      _popupEnable = state;
    });
  }

  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    final screenWidth = screenSize.width;
    final screenHeight = screenSize.height;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(right: 30),
              child: const Text('触达开关', style: TextStyle(fontSize: 22)),
            ),
            CupertinoSwitch(
                value: _popupEnable,
                onChanged: (bool value) {
                  setState(() {
                    _popupEnable = !_popupEnable;
                    GrowingTouch.eventPopupEnable = _popupEnable;
                  });
                })
          ],
        ),
        Container(
          width: screenWidth,
          padding: EdgeInsets.only(left: 10, right: 10, top: 10),
          child: CupertinoButton(
            child: Text('触发一个埋点事件'),
            onPressed: () {
              GrowingIO.track("touch1");
            },
            color: Colors.teal,
          ),
        ),
        Container(
          width: screenWidth,
          padding: EdgeInsets.only(left: 10, right: 10, top: 10),
          child: CupertinoButton(
            child: Text('打开一个页面'),
            onPressed: () {
              Navigator.push(context, CupertinoPageRoute(builder: (context) => SecondScreen()));
            },
            color: Colors.teal,
          ),
        ),
        Container(
          width: screenWidth,
          padding: EdgeInsets.only(left: 10, right: 10, top: 10),
          child: CupertinoButton(
            child: Text('注册弹窗监听'),
            onPressed: () {
              GrowingTouch.eventPopupListener = EventPopupListener(onLoadSuccess: (eventId, eventType) => print('onLoadSuccess: eventId = ' + eventId + ', eventType = ' + eventType));
            },
            color: Colors.teal,
          ),
        ),
        Container(
          width: screenWidth,
          padding: EdgeInsets.only(left: 10, right: 10, top: 10),
          child: CupertinoButton(
            child: Text('注销弹窗监听'),
            onPressed: () {
              GrowingTouch.eventPopupListener = null;
            },
            color: Colors.teal,
          ),
        ),
      ],
    );
  }
}

class SecondScreen extends StatelessWidget {
  bool _open = false;

  @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance.addPostFrameCallback((callback) {
      if (!_open) {
        _open = true;
        print("Page first open ");
        GrowingIO.track("TestPageOpen");
      }
    });

    return Scaffold(
      appBar: AppBar(
        title: Text("Second Screen"),
      ),
      body: Center(
        child: CupertinoButton(
          onPressed: () {
            Navigator.pop(context);
          },
          child: Text('Go back!'),
          color: Colors.teal,
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_growingio_touch: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_growingio_touch/flutter_growingio_touch.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Mar 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

24 out of 24 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/flutter_growingio_touch.dart.

Run flutter format to format lib/flutter_growingio_touch.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test