incognia_flutter 1.1.1 incognia_flutter: ^1.1.1 copied to clipboard
A plugin for Incognia's SDK.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:incognia_flutter/custom_event.dart';
import 'package:incognia_flutter/incognia_flutter.dart';
import 'package:incognia_flutter/incognia_options.dart';
void main() {
runApp(const MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late TextEditingController _textEditingController;
final _incogniaFlutterPlugin = IncogniaFlutter();
String _sdkInitCalled = "Not called yet";
@override
void initState() {
super.initState();
_incogniaFlutterPlugin.initSdk();
// Comment the line above and uncomment the following lines to initialize the SDK with options:
// _incogniaFlutterPlugin.initSdkWithOptions(
// IncogniaOptions(
// androidOptions:
// AndroidOptions(appId: "YOUR_ANDROID_APP_ID", logEnabled: true),
// iOSOptions: IOSOptions(appId: "YOUR_IOS_APP_ID", logEnabled: true)),
// );
_sdkInitCalled = "Init Called";
_textEditingController = TextEditingController();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(children: [
Text('SDK Init State: $_sdkInitCalled\n'),
TextField(
controller: _textEditingController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Account ID',
),
onSubmitted: (String value) {
_incogniaFlutterPlugin.setAccountId(value);
},
),
TextButton(
onPressed: () {
_incogniaFlutterPlugin
.setAccountId(_textEditingController.text);
},
child: const Text('Set Account ID'),
),
TextButton(
onPressed: () {
_incogniaFlutterPlugin.clearAccountId();
},
child: const Text('Clear Account ID'),
),
TextButton(
onPressed: () {
var customEvent = CustomEvent(tag: 'custom_event', properties: {
'property1': 'value1',
'property2': 0,
'property3': 2.8,
'property4': true,
});
_incogniaFlutterPlugin.sendCustomEvent(customEvent);
},
child: const Text('Send Custom Event'),
),
TextButton(
onPressed: () async {
var token = await _incogniaFlutterPlugin.generateRequestToken();
if (context.mounted) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Request Token'),
content: Text(token ?? 'null'),
actions: <Widget>[
TextButton(
onPressed: () async {
await Clipboard.setData(
ClipboardData(text: token ?? 'null'));
},
child: const Text('Copy to clipboard'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Close'),
),
],
);
},
);
}
},
child: const Text('Generate Request Token'),
),
]),
),
),
);
}
}