qoreidsdk 1.1.0 copy "qoreidsdk: ^1.1.0" to clipboard
qoreidsdk: ^1.1.0 copied to clipboard

QoreID flutter plugin.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:qoreidsdk/qoreidsdk.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    _initQoreidResults();
  }

  void _initQoreidResults() {
    Qoreidsdk.onResult((data) async {
      print(data);
      if (data["data"] != null) {
        print(data["data"]["verification"]["id"]);
      }
    });
  }

  void _launchQoreid(QoreidData data) async {
    await Qoreidsdk.launchQoreid(data);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: MyForm(_launchQoreid));
  }
}

class MyForm extends StatefulWidget {
  final Function(QoreidData data) onSubmit;

  const MyForm(this.onSubmit, {super.key});

  @override
  _MyFormState createState() => _MyFormState();
}

class _MyFormState extends State<MyForm> {
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

  Map<String, dynamic> formData = {
    "addressData": {
      "address": "",
      "city": "",
      "lga": "",
    },
    "applicantData": {
      "email": "",
      "firstName": "Emma",
      "gender": "",
      "lastName": "Emmanuel",
      "middleName": "",
      "phoneNumber": "08023902309",
    },
    "clientId": "",
    "customerReference": "",
    "flowId": 0,
    "identityData": {
      "idNumber": "",
      "idType": "",
    },
    "ocrAcceptedDocuments": "",
    "productCode": "",
  };

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Verification Form'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Form(
          key: _formKey,
          child: SingleChildScrollView(
            child: Column(
              children: [
                TextFormField(
                  decoration: const InputDecoration(labelText: "Client ID"),
                  initialValue: "WSK4X7QLFV3CVRVFZB43",// "FQOI6QT6XQD3QJRYCO35", //RHMROERTFJQS4LBZO3R8 / cus-asd232323232,
                  onSaved: (value) {
                    formData["clientId"] = value;
                  },
                ),
                TextFormField(
                  decoration: const InputDecoration(labelText: "Product Code"),
                  initialValue: "liveness",
                  onSaved: (value) {
                    formData["productCode"] = value;
                  },
                ),
                TextFormField(
                  decoration:
                      const InputDecoration(labelText: "Customer Reference"),
                  initialValue: "CUST001",
                  onSaved: (value) {
                    formData["customerReference"] = value;
                  },
                ),
                TextFormField(
                  keyboardType: TextInputType.number,
                  decoration: const InputDecoration(
                    labelText: "Flow ID",
                  ),
                  initialValue: "947", // "932",
                  onSaved: (value) {
                    formData["flowId"] = int.tryParse(value ?? "0");
                  },
                ),
                _buildNestedFormField("identity Data", ["idNumber", "idType"]),
                _buildNestedFormField("address Data", [
                  "address",
                  "city",
                  "lga",
                ]),
                _buildNestedFormField("applicant Data", [
                  "email",
                  "firstName",
                  "gender",
                  "lastName",
                  "middleName",
                  "phoneNumber-"
                ]),
                TextFormField(
                    decoration: const InputDecoration(
                        labelText: "OCR Accepted Documents",
                        hintText: "comma separated strings"),
                    initialValue:
                        "DRIVERS_LICENSE_NGA,VOTERS_CARD_NGA,NIN_SLIP_NGA,PASSPORT_NGA",
                    onSaved: (value) {
                      formData["ocrAcceptedDocuments"] = value;
                    }),
                Container(
                  padding: const EdgeInsets.all(20.0),
                  width: double.infinity,
                  child: ElevatedButton(
                    onPressed: () {
                      // if (!_formKey.currentState!.isNull) {
                      _formKey.currentState!.save();
                      final data = QoreidData(
                          addressData: formData['addressData'] ?? {},
                          applicantData: formData['applicantData'],
                          clientId: formData['clientId'] ?? '',
                          customerReference:
                              formData['customerReference'] ?? '',
                          flowId: formData['flowId'],
                          identityData: formData['identityData'] ?? {},
                          ocrAcceptedDocuments:
                              formData['ocrAcceptedDocuments'] ?? '',
                          productCode: formData['productCode'] ?? '');
                      widget.onSubmit(data);
                      // }
                    },
                    child: const Text('Submit'),
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _buildNestedFormField(String fieldName, List<String> labels) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 8.0),
          child: Text(
            fieldName.toUpperCase(), // Capitalize the text
            style: const TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold, // Set it to bold
            ),
          ),
        ),
        ...labels.map((label) {
          return Column(
            children: [
              TextFormField(
                decoration: InputDecoration(labelText: label),
                onSaved: (value) {
                  formData[fieldName.replaceAll(RegExp(" "), "")][label] =
                      value;
                },
                validator: (value) {
                  if (fieldName == "addressData" && value!.isEmpty) {
                    return "$label is required";
                  }
                  return null;
                },
              ),
            ],
          );
        })
      ],
    );
  }
}