vnid 0.0.2 copy "vnid: ^0.0.2" to clipboard
vnid: ^0.0.2 copied to clipboard

project vnid

example/lib/main.dart

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

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

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _vnidPlugin = Vnid();
  bool debug = false;
  bool requiredEmail = false;
  bool editable = false;
  String appID = "ONBOARD";
  String appCode = "ONBOARD";
  String email = "";
  String phone = "";
  String partnerUserID = "";
  String error = "";

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

  void _setupEventListener() {
    _vnidPlugin.eventStream.listen(
      (event) {
        print('Kyc received event: $event');
        if (event is Map<String, dynamic>) {
          setState(
            () {
              if (event['type'] == 'success') {
                //TODO:
              } else if (event['type'] == 'screen') {
                //TODO:
              } else if (event['type'] == 'error') {
                //TODO:
              }
            },
          );
        }
      },
      onError: (error) {
        print('Kyc error: $error');
        setState(() {
          //TODO:
        });
      },
    );
  }

  Future<void> startKyc() async {
    try {
      await _vnidPlugin.startKyc(debug, appID, appCode, email, phone, editable,
          partnerUserID, requiredEmail);
    } catch (e) {}
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SafeArea(
            child: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                margin: const EdgeInsets.only(
                    left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
                child: TextField(
                  onSubmitted: (String value) async {
                    setState(() {
                      appID = value;
                    });
                  },
                  obscureText: false,
                  decoration: const InputDecoration(
                    label: Text("AppID"),
                    border: OutlineInputBorder(),
                  ),
                  controller: TextEditingController(text: appID),
                ),
              ),
              Container(
                margin: const EdgeInsets.only(
                    left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
                child: TextField(
                  onSubmitted: (String value) async {
                    setState(() {
                      appCode = value;
                    });
                  },
                  controller: TextEditingController(text: appCode),
                  obscureText: false,
                  decoration: const InputDecoration(
                    label: Text("appCode"),
                    border: OutlineInputBorder(),
                  ),
                ),
              ),
              Container(
                margin: const EdgeInsets.only(
                    left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
                child: TextField(
                  onSubmitted: (String value) async {
                    setState(() {
                      email = value;
                    });
                  },
                  controller: TextEditingController(text: email),
                  obscureText: false,
                  decoration: const InputDecoration(
                    label: Text("Email"),
                    border: OutlineInputBorder(),
                  ),
                ),
              ),
              Container(
                margin: const EdgeInsets.only(
                    left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
                child: TextField(
                  onSubmitted: (String value) async {
                    setState(() {
                      phone = value;
                    });
                  },
                  controller: TextEditingController(text: phone),
                  obscureText: false,
                  decoration: const InputDecoration(
                    label: Text("Phone"),
                    border: OutlineInputBorder(),
                  ),
                ),
              ),
              Container(
                margin: const EdgeInsets.only(
                    left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
                child: TextField(
                  onSubmitted: (String value) async {
                    setState(() {
                      partnerUserID = value;
                    });
                  },
                  controller: TextEditingController(text: partnerUserID),
                  obscureText: false,
                  decoration: const InputDecoration(
                    label: Text("partnerUserID"),
                    border: OutlineInputBorder(),
                  ),
                ),
              ),
              Container(
                margin: const EdgeInsets.only(
                    left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
                child: Row(
                  children: [
                    if (debug) const Text("PROD") else const Text("UAT"),
                    Switch(
                      value: debug,
                      onChanged: (bool value) {
                        setState(() {
                          debug = value;
                        });
                      },
                    ),
                  ],
                ),
              ),
              Container(
                margin: const EdgeInsets.only(
                    left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
                child: ElevatedButton(
                  onPressed: () {
                    startKyc();
                  },
                  child: const Text("Start"),
                ),
              )
            ],
          ),
        )),
      ),
    );
  }
}
0
likes
135
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

project vnid

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on vnid

Packages that implement vnid