incognia_flutter 2.0.0
incognia_flutter: ^2.0.0 copied to clipboard
A plugin for Incognia's SDK.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:incognia_flutter/card_info.dart';
import 'package:incognia_flutter/custom_event.dart';
import 'package:incognia_flutter/event_address.dart';
import 'package:incognia_flutter/event_location.dart';
import 'package:incognia_flutter/incognia_flutter.dart';
import 'package:incognia_flutter/incognia_options.dart';
import 'package:incognia_flutter/login_event.dart';
import 'package:incognia_flutter/onboarding_event.dart';
import 'package:incognia_flutter/payment_address.dart';
import 'package:incognia_flutter/payment_coupon.dart';
import 'package:incognia_flutter/payment_event.dart';
import 'package:incognia_flutter/payment_method.dart';
import 'package:incognia_flutter/payment_value.dart';
import 'package:incognia_flutter/request_token_with_status.dart';
import 'package:permission_handler/permission_handler.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)),
// );
WidgetsBinding.instance.addPostFrameCallback((_) async {
await Permission.locationWhenInUse.request();
});
_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: () {
_incogniaFlutterPlugin.setLocationEnabled(true);
},
child: const Text('Enable Location'),
),
TextButton(
onPressed: () {
_incogniaFlutterPlugin.setLocationEnabled(false);
},
child: const Text('Disable Location'),
),
TextButton(
onPressed: () {
var customEvent = CustomEvent(
accountId: "flutter_account_id",
externalId: "flutter_external_id",
tag: 'flutter_tag',
status: 'flutter_status',
address: EventAddress(
locale: 'en-US',
countryName: 'United States',
countryCode: 'US',
state: 'New York',
city: 'New York City',
neighborhood: 'Manhattan',
number: '350',
street: 'Fifth Avenue',
postalCode: '10118',
latitude: 40.748817,
longitude: -73.985428,
addressLine: '350 Fifth Avenue, New York City, NY 10118, United States',
),
properties: {
'stringProperty': 'value1',
'intProperty': 0,
'longProperty': 12345678901234,
'doubleProperty': 2.8,
'boolProperty': true,
});
_incogniaFlutterPlugin.sendCustomEvent(customEvent);
},
child: const Text('Send Custom Event'),
),
TextButton(
onPressed: () {
var onboardingEvent = OnboardingEvent(
accountId: "flutter_account_id",
externalId: "flutter_external_id",
tag: 'flutter_tag',
status: 'flutter_status',
address: EventAddress(
locale: 'en-US',
countryName: 'United States',
countryCode: 'US',
state: 'New York',
city: 'New York City',
neighborhood: 'Manhattan',
number: '350',
street: 'Fifth Avenue',
postalCode: '10118',
latitude: 40.748817,
longitude: -73.985428,
addressLine: '350 Fifth Avenue, New York City, NY 10118, United States',
),
properties: {
'stringProperty': 'value1',
'intProperty': 0,
'longProperty': 12345678901234,
'doubleProperty': 2.8,
'boolProperty': true,
});
_incogniaFlutterPlugin.sendOnboardingEvent(onboardingEvent);
},
child: const Text('Send Onboarding Event'),
),
TextButton(
onPressed: () {
var loginEvent = LoginEvent(
accountId: "flutter_account_id",
externalId: "flutter_external_id",
tag: 'flutter_tag',
status: 'flutter_status',
location: EventLocation(
latitude: 40.748817,
longitude: -73.985428,
timestamp: 1234568901234,
),
properties: {
'stringProperty': 'value1',
'intProperty': 0,
'longProperty': 12345678901234,
'doubleProperty': 2.8,
'boolProperty': true,
});
_incogniaFlutterPlugin.sendLoginEvent(loginEvent);
},
child: const Text('Send Login Event'),
),
TextButton(
onPressed: () {
var paymentEvent = PaymentEvent(
accountId: "flutter_account_id",
externalId: "flutter_external_id",
storeId: 'flutter_store_id',
tag: 'flutter_tag',
status: 'flutter_status',
location: EventLocation(
latitude: 40.748817,
longitude: -73.985428,
timestamp: 1234568901234,
),
paymentValue: PaymentValue(
amount: 99.99,
currency: 'USD',
installments: 1,
discountAmount: 10.00,
),
paymentCoupon: PaymentCoupon(
type: PaymentCoupon.fixedValueType,
value: 10.00,
maxDiscount: 15.00,
id: 'incognia_coupon',
name: 'Incognia Sale',
),
paymentMethods: [
PaymentMethod(
type: PaymentMethod.creditCardType,
identifier: 'incognia_credit_card_identifier',
brand: PaymentMethod.visaBrand,
creditCardInfo: CardInfo(
bin: '411111',
lastFourDigits: '1111',
expiryYear: '2025',
expiryMonth: '12',
),
),
PaymentMethod(
type: PaymentMethod.debitCardType,
identifier: 'incognia_debit_card_identifier',
brand: PaymentMethod.mastercardBrand,
debitCardInfo: CardInfo(
bin: '522222',
lastFourDigits: '1234',
expiryYear: '2026',
expiryMonth: '01',
),
),
],
addresses: [
PaymentAddress(
type: PaymentAddress.billingType,
address: EventAddress(
locale: 'en-US',
countryName: 'United States',
countryCode: 'US',
state: 'New York',
city: 'New York City',
neighborhood: 'Manhattan',
number: '350',
street: 'Fifth Avenue',
postalCode: '10118',
latitude: 40.748817,
longitude: -73.985428,
addressLine: '350 Fifth Avenue, New York City, NY 10118, United States',
),
),
PaymentAddress(
type: PaymentAddress.shippingType,
address: EventAddress(
locale: 'en-US',
countryName: 'United States',
countryCode: 'US',
state: 'New York',
city: 'New York City',
neighborhood: 'Manhattan',
number: '350',
street: 'Fifth Avenue',
postalCode: '10118',
latitude: 40.748817,
longitude: -73.985428,
addressLine: '350 Fifth Avenue, New York City, NY 10118, United States',
),
),
],
properties: {
'stringProperty': 'value1',
'intProperty': 0,
'longProperty': 12345678901234,
'doubleProperty': 2.8,
'boolProperty': true,
});
_incogniaFlutterPlugin.sendPaymentEvent(paymentEvent);
},
child: const Text('Send Payment Event'),
),
TextButton(
onPressed: () async {
var tokenWithStatus = await _incogniaFlutterPlugin.generateRequestTokenWithStatus();
var message = (tokenWithStatus != null)
? (tokenWithStatus.status == RequestTokenStatus.success) ? 'Token: ${tokenWithStatus.token}' : 'Token Status: ${tokenWithStatus.status.name}'
: 'Failed to generate request token';
if (context.mounted) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Request Token'),
content: Text(message),
actions: <Widget>[
TextButton(
onPressed: () async {
await Clipboard.setData(
ClipboardData(text: tokenWithStatus?.token ?? 'null'));
},
child: const Text('Copy to clipboard'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Close'),
),
],
);
},
);
}
},
child: const Text('Generate Request Token With Status'),
),
TextButton(
onPressed: () {
_incogniaFlutterPlugin.refreshLocation();
},
child: const Text('Refresh Location'),
),
]),
),
),
);
}
}