ironchip_lbfraud 0.0.1 ironchip_lbfraud: ^0.0.1 copied to clipboard
Flutter plugin designed for Location Fraud Detection, powered by the analysis of environmental signals to detect and prevent fraudulent activities effectively.
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:math';
import 'package:flutter/services.dart';
import 'package:ironchip_lbfraud/ironchip_lbfraud.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _lbfraudPlugin = IronchipLbfraud();
String apiKey =
"APIKEY"; // Replace APIKEY with the desired generated api key.
bool _isLbfraudInitialized = false;
String userID = "john.doe@gmail.com"; // User identifier
String _showResult = "";
bool _resultError = false;
@override
void initState() {
super.initState();
}
// LBFraud methods are asynchronous, so we initialize in an async method.
Future<void> initLBFraudState() async {
try {
// Replace APIKEY with the desired generated api key.
// By default our SDK target to the production environment.
// In case you desire to target a diferent enviroment:
// LBFraudSDK fraud = new LbfraudFlutterPlugin.initFraudSDK("APIKEY", env: Environment.testing);
await _lbfraudPlugin.initFraudSDK(apiKey);
_isLbfraudInitialized = true;
} catch (e) {
_isLbfraudInitialized = false;
}
setState(() {
_isLbfraudInitialized = _isLbfraudInitialized;
});
}
String generateRandomTransactionID(int length) {
const _chars =
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
Random _rnd = Random();
return String.fromCharCodes(Iterable.generate(
length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));
}
Future<void> sendTransaction() async {
try {
// TransactionID (required,unique): transaction identifier request for fraud results
// UserID (required): User identifier
// extraData (optional): extra information for analysis
// You can omit the await in case the result of the action isn't necessary
var result = await _lbfraudPlugin
.sendTransaction(generateRandomTransactionID(10), userID, {});
_showResult = result!;
_resultError = false;
} catch (e) {
_showResult = e.toString();
_resultError = true;
}
setState(() {
_resultError = _resultError;
_showResult = _showResult;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Ironchip LBFraud example app'),
backgroundColor: Color(0xFF005255),
),
body: Container(
margin: EdgeInsets.all(40.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
onChanged: (value) {
apiKey = value;
},
decoration: const InputDecoration(labelText: "API Key"),
),
SizedBox(height: 20),
Text(
_isLbfraudInitialized
? "LBFraud initialized"
: "LBFraud is not initialized",
style: TextStyle(
color: _isLbfraudInitialized
? Color(0xFF495c11f)
: Color(0xFFF44336),
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: initLBFraudState,
style: ElevatedButton.styleFrom(
primary: Color(0xFF495c11f), // Set button color to #4eed56
),
child: Text('Initialize LBFraud'),
),
TextField(
onChanged: (value) {
userID = value;
},
decoration: const InputDecoration(labelText: "User ID"),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _isLbfraudInitialized ? sendTransaction : null,
style: ElevatedButton.styleFrom(
primary: Color(0xFF495c11f), // Set button color to #4eed56
),
child: Text('Send Transaction'),
),
SizedBox(height: 20),
Text(
_showResult,
style: TextStyle(
color: _resultError ? Color(0xFFF44336) : Colors.black,
),
),
],
),
),
),
));
}
}