Visit pub.dev to learn more about our flutter plugin:

pub version

Once you have set up your project correctly, required the necessary permissions, then you just have to import the package with:

import 'package:ironchip_lbfraud_plugin/ironchip_lbfraud.dart';

In order to send transaction, you must first initialize the sdk by providing a valid api key.

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

Once the service has been initialized, you can now perform transactions:

    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(transactionID, userID, {});

      _showResult = result!;
      _resultError = false;
    } catch (e) {
      _showResult = e.toString();
      _resultError = true;
    }

Although the sendTransaction is async, it’s not necessary to perform an ‘await’ unless you want to check the actual result of the action. In addition, if you want to use a specific proxy when performing a transaction, you can configure it using:

   try {
      var result =
          await _lbfraudPlugin.setProxy(host, port);
    } catch (e) {
    }

Example

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,
                ),
              ),
            ],
          ),
        ),
      ),
    ));
  }
}