blotoutfluttersdk 0.0.11
blotoutfluttersdk: ^0.0.11 copied to clipboard

Flutter Android iOS

A new flutter plugin project.

example/lib/main.dart

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

/// Set your Blotout token here before run the example app.
const YOUR_BLOTOUT_TOKEN = 'XYXXNCSNPWWQCGV'; //'XYXXNCSNPWWQCGV';
// Android Token 6QZV6A4PRQT9VVV
//iOS APP token XYXXNCSNPWWQCGV
void main(List<String> args) {
  String blotoutToken = args.isNotEmpty ? args[0] : YOUR_BLOTOUT_TOKEN;
  runApp(MyApp(blotoutToken));
}

class MyApp extends StatefulWidget {
  final String _blotoutToken;

  MyApp(this._blotoutToken);

  @override
  _MyAppState createState() => _MyAppState(_blotoutToken);
}

class _MyAppState extends State<MyApp> {
  String _blotoutToken;
  String _resultMessage = '';

  _MyAppState(this._blotoutToken);

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // 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;
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> content;
    if (_blotoutToken == null || _blotoutToken.trim().length == 0) {
      content = [Text('Your BlotoutSDK Token was not informed')];
    } else {
      content = createButtons(context);
    }
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Blotout.io Blotout Plugin Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Text(
                _resultMessage,
                key: Key('resultMessage'),
              ),
              Column(
                children: content,
              ),
            ],
          ),
        ),
      ),
    );
  }

  List<Widget> createButtons(BuildContext context) {
    return [
      buttonGetInstance(context),
      buttonTrackEvent(context),
      buttonTrackPHIEvent(context),
      buttonTrackPIIEvent(context),
      buttonDeviceCompromisedEvent(context),
      buttonStartEvent(context),
      buttonEndEvent(context),
      buttonLogEventWithTime(context)
    ];
  }

  Widget buttonGetInstance(BuildContext context) => RaisedButton(
      key: Key('getInstance'),
      child: Text('Get an instance of Blotout plugin'),
      onPressed: () => getInstance());

  Widget buttonTrackEvent(BuildContext context) => RaisedButton(
      key: Key('trackEvent'),
      child: Text('Track an event'),
      onPressed: () => trackEvent());

  Widget buttonTrackPHIEvent(BuildContext context) => RaisedButton(
      key: Key('trackPHIEvent'),
      child: Text('Track PHI Event'),
      onPressed: () => trackPHIEvent());

  Widget buttonTrackPIIEvent(BuildContext context) => RaisedButton(
      key: Key('trackPIIEvent'),
      child: Text('Track PII Event'),
      onPressed: () => trackPIIEvent());

  Widget buttonDeviceCompromisedEvent(BuildContext context) => RaisedButton(
      key: Key('isDevice Compromised'),
      child: Text('isDevice Compromised'),
      onPressed: () => isDeviceCompromised());

  Widget buttonLogEventWithTime(BuildContext context) => RaisedButton(
      key: Key('LogEventWithTime'),
      child: Text('LogEventWithTime'),
      onPressed: () => trackEventWithTime());

  Widget buttonStartEvent(BuildContext context) => RaisedButton(
      key: Key('buttonStartEvent'),
      child: Text('Start Event Tracking'),
      onPressed: () => trackStartEvent());

  Widget buttonEndEvent(BuildContext context) => RaisedButton(
      key: Key('buttonEndEvent'),
      child: Text('End Event Tracking'),
      onPressed: () => trackEndEvent());

  void getInstance() {
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .initBlotoutSDK(_blotoutToken, "http://dev.blotout.io")
        .then((success) {
      setState(() {
        _resultMessage = 'Instance created with success!';
      });
    });
  }

  void trackEvent() {
    Map<String, String> properties = {
      "Button Pressed": "A LogEvent button was pressed"
    };
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .logEvent('logEvent', properties);
    setState(() {
      _resultMessage = 'Event sent with success!';
    });
  }

  void trackEventWithTime() {
    Map<String, String> properties = {
      "logEventWithTime": "A logEventWithTime button was pressed"
    };
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .logEventWithTime('logEventWithTime', properties, DateTime.now());
    setState(() {
      _resultMessage = 'Event sent with success!';
    });
  }

  void trackStartEvent() {
    Map<String, String> properties = {
      "trackStartEvent": "A trackStartEvent button was pressed"
    };
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .startTimedEvent('logTimeEvent', properties);
    setState(() {
      _resultMessage = 'Event sent with success!';
    });
  }

  void trackEndEvent() {
    Map<String, String> properties = {
      "trackEndEvent": "A trackEndEvent button was pressed"
    };
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .endTimedEvent('logTimeEvent', properties);
    setState(() {
      _resultMessage = 'Event sent with success!';
    });
  }

  void trackPHIEvent() {
    Map<String, String> properties = {
      "Button Pressed": "A logPHIEvent button was pressed"
    };
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .logPHIEvent('logPHIEvent', properties, DateTime.now());
    setState(() {
      _resultMessage = 'Event sent with success!';
    });
  }

  void trackPIIEvent() {
    Map<String, String> properties = {
      "Button Pressed": "A logPIIEvent button was pressed"
    };
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .logPIIEvent('logPIIEvent', properties, DateTime.now());
    setState(() {
      _resultMessage = 'Event sent with success!';
    });
  }

  void isDeviceCompromised() {
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .isDeviceCompromised()
        .then((success) {
      setState(() {
        if (success) {
          _resultMessage = 'Device Compromised!';
        } else {
          _resultMessage = 'Device is not compromised!';
        }
      });
    });
  }
}
1
likes
80
pub points
4%
popularity

A new flutter plugin project.

Homepage

Documentation

API reference

Uploader

ankur@blotout.io

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on blotoutfluttersdk