blotoutfluttersdk 0.0.4 copy "blotoutfluttersdk: ^0.0.4" to clipboard
blotoutfluttersdk: ^0.0.4 copied to clipboard

outdated

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 = 'abcd';

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 [
      buttonSetEndPoint(context),
      buttonGetInstance(context),
      buttonTrackEvent(context),
      buttonTrackPHIEvent(context),
      buttonTrackPIIEvent(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 buttonSetEndPoint(BuildContext context) => RaisedButton(
      key: Key('setEndPoint'),
      child: Text('Set End Point'),
      onPressed: () => setEndPoint());

  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());

  void getInstance() {
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .initBlotoutSDK(_blotoutToken, _blotoutToken, false)
        .then((success) {
      setState(() {
        _resultMessage = 'Instance created with success!';
      });
    });
  }

  void setEndPoint() {
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .setSDKEndPointUrl("http://dev.blotout.io");
    setState(() {
      _resultMessage = 'Instance set sdk endpoint!';
    });
  }

  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 trackPHIEvent() {
    Map<String, String> properties = {
      "Button Pressed": "A logPHIEvent button was pressed"
    };
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .logPHIEvent('logPHIEvent', properties, new DateTime(2020));
    setState(() {
      _resultMessage = 'Event sent with success!';
    });
  }

  void trackPIIEvent() {
    Map<String, String> properties = {
      "Button Pressed": "A logPIIEvent button was pressed"
    };
    BlotoutAnalyticsAPI.blotoutAnalyticsInstance
        .logPIIEvent('logPIIEvent', properties, new DateTime(2020));
    setState(() {
      _resultMessage = 'Event sent with success!';
    });
  }
}
1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A new flutter plugin project.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on blotoutfluttersdk