hypertrack_plugin 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 67

hypertrack_plugin #

Plugin for HyperTrack SDK.

Usage #

To use this plugin, add hypertrack_plugin as a dependency in your pubspec.yaml file.

Example #

// Import package
import 'package:hypertrack_plugin/hypertrack.dart';

// Instantiate it
final sdk = await HyperTrack.initialize(my_publishable_key);


// Set device name
sdk.setDeviceName("Elvis");

// Get device id
final deviceId = await sdk.getDeviceId();

Visit https://hypertrack.com/ for more.

[0.1.0] - 2020-03-24 #

Added

  • Initial release.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:hypertrack_plugin/hypertrack.dart';

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

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

class _MyAppState extends State<MyApp> {
  static const key = 'paste_your_key_here';
  String _result = 'Not initialized';
  String _deviceId = '';
  HyperTrack sdk;

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initializeSdk() async {

    HyperTrack.enableDebugLogging();
    // Initializer is just a helper class to get the actual sdk instance
    String result = 'failure';
    try {
      sdk = await HyperTrack.initialize(key);
      result = 'initialized';
      sdk.setDeviceName("Flutter Elvis");
      sdk.setDeviceMetadata({"source": "flutter sdk"});
      sdk.onTrackingStateChanged.listen((TrackingStateChange event) {
        if (mounted) {
          setState(() {_result = '$event';});
        }
      });
    } catch (e) {
      print(e);
    }


    final deviceId = (sdk == null)? "unknown" : await sdk.getDeviceId();

    // 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(() {
      _result = result;
      _deviceId = deviceId;
    });
  }

  void start() => sdk.start();

  void stop() => sdk.stop();

  void syncDeviceSettings() => sdk.syncDeviceSettings();


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'Initialization result is $_result',
              ),
              Text(
                'Device id is $_deviceId',
              ),
              ButtonBar(
                children:[
                  FlatButton(
                      onPressed: start,
                      child:Text("Start")
                  ),
                  FlatButton(
                      onPressed: initializeSdk,
                      child:Text("Initialize")
                  ),
                  FlatButton(
                      onPressed: stop,
                      child:Text("Stop")
                  ),
                  FlatButton(
                      onPressed: syncDeviceSettings,
                      child:Text("Sync")
                  ),
                ],
                alignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.max,
              ),
            ],
          ),        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  hypertrack_plugin: ^0.1.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:hypertrack_plugin/hypertrack.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
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]
67
Learn more about scoring.

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

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health issues and suggestions

Document public APIs. (-1 points)

25 out of 25 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/hypertrack.dart.

Run flutter format to format lib/hypertrack.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.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test