blotoutfluttersdk 0.0.7 blotoutfluttersdk: ^0.0.7 copied to clipboard
A new flutter plugin project.
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 = '6QZV6A4PRQT9VVV'; //'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 [
buttonSetEndPoint(context),
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 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());
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, _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 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!';
}
});
});
}
}