hungtm5_kyc 1.2.0 copy "hungtm5_kyc: ^1.2.0" to clipboard
hungtm5_kyc: ^1.2.0 copied to clipboard

onboarding

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:hungtm5_kyc/hungtm5_kyc.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 pvcomBankKyc = Kyc();
  String urlConfirm = "";
  String phone = "";
  String email = "";
  String kycStatus = "Idle";

  @override
  void initState() {
    super.initState();
    _setupEventListener();
  }

  void _setupEventListener() {
    pvcomBankKyc.eventStream.listen(
      (event) {
        print('Kyc received event: $event');
        if (event is Map<String, dynamic>) {
          setState(() {
            if (event['type'] == 'success') {
              kycStatus = "Success: ${event['message']}";
            } else if (event['type'] == 'screen') {
              kycStatus = "Screen changed: ${event['message']}";
            } else if (event['type'] == 'error') {
              kycStatus = "Error: ${event['message']}";
            }
          });
        }
      },
      onError: (error) {
        print('Kyc error: $error');
        setState(() {
          kycStatus = "Error: $error";
        });
      },
    );
  }

  Future<void> _startEKyc(email, phone, editable, requireEmail) async {
    setState(
      () {
        kycStatus = "Starting KYC...";
      },
    );
    try {
      KycConfig config = KycConfig(
          env: Environment.UAT,
          debug: true,
          appCode: "ONBOARD",
          appId: "ONBOARD",
          partnerUserId: "partner.user.id",
          email: email,
          phone: phone,
          requireEmail: requireEmail);
      await pvcomBankKyc.eKyc(config);
    } catch (e) {
      setState(() {
        kycStatus = "Error starting KYC: $e";
      });
    }
  }

  Future<void> _trustData() async {
    setState(() {
      kycStatus = "Starting KYC Liveness...";
    });
    try {
      KycConfig config = KycConfig(
          env: Environment.UAT,
          debug: true,
          appCode: "ONBOARD",
          appId: "ONBOARD",
          partnerUserId: "partner.user.id",
          email: email,
          phone: phone,
          trustDataConfirm: urlConfirm);
      await pvcomBankKyc.eKycTrustData(config);
    } catch (e) {
      setState(() {
        kycStatus = "Error starting KYC Liveness: $e";
      });
    }
  }

  Future<void> _trustDataV2() async {
    setState(() {
      kycStatus = "Starting KYC by Data...";
    });
    try {
      KycConfig config = KycConfig(
        env: Environment.UAT,
        debug: true,
        appCode: "VIETPAY",
        appId: "VIETPAY",
        partnerUserId: "partner.user.id",
        email: email,
        phone: phone,
      );
      await pvcomBankKyc.eKycTrustDataV2(config);
    } catch (e) {
      setState(() {
        kycStatus = "Error starting KYC by Data: $e";
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('PVComBank KYC Example'),
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(16),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  'KYC Status: $kycStatus',
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(height: 20),
                ElevatedButton(
                  onPressed: () {
                    _startEKyc(
                      email,
                      phone,
                      true,
                      false,
                    );
                  },
                  child: const Text("Start KYC"),
                ),
                const SizedBox(height: 20),
                TextField(
                  onChanged: (text) {
                    urlConfirm = text;
                  },
                  decoration: const InputDecoration(
                    labelText: 'Enter URL confirm',
                    border: OutlineInputBorder(),
                    helperText: "URL is only used for liveness feature",
                  ),
                ),
                TextField(
                  onChanged: (text) {
                    phone = text;
                  },
                  decoration: const InputDecoration(
                    labelText: 'Enter phone',
                    border: OutlineInputBorder(),
                  ),
                ),
                const SizedBox(
                  height: 8,
                ),
                TextField(
                  onChanged: (text) {
                    email = text;
                  },
                  decoration: const InputDecoration(
                    labelText: 'Enter email',
                    border: OutlineInputBorder(),
                  ),
                ),
                const SizedBox(height: 20),
                ElevatedButton(
                  onPressed: _trustData,
                  child: const Text("Liveness"),
                ),
                const SizedBox(height: 20),
                ElevatedButton(
                  onPressed: _trustDataV2,
                  child: const Text("VietPay"),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
0
points
164
downloads

Publisher

unverified uploader

Weekly Downloads

onboarding

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on hungtm5_kyc

Packages that implement hungtm5_kyc