okyc_flutter 0.1.1 copy "okyc_flutter: ^0.1.1" to clipboard
okyc_flutter: ^0.1.1 copied to clipboard

OKYC identity verification for Flutter: the hosted KYC/KYB flow in a secure, full-screen WebView with native permissions, file picking and results.

example/lib/main.dart

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

void main() => runApp(const ExampleApp());

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'OKYC Flutter example',
      theme: ThemeData(colorSchemeSeed: const Color(0xFF3B5BDB), useMaterial3: true),
      home: const ExampleHome(),
    );
  }
}

/// A session URL to start with, e.g. `flutter run --dart-define=OKYC_SESSION_URL=<url>`.
/// Your server creates sessions (`POST /v1/sessions` with its secret key) and gives the app the `url`.
const _initialSessionUrl = String.fromEnvironment('OKYC_SESSION_URL');

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

  @override
  State<ExampleHome> createState() => _ExampleHomeState();
}

class _ExampleHomeState extends State<ExampleHome> {
  final _url = TextEditingController(text: _initialSessionUrl);
  final _log = <String>[];
  String? _result;

  @override
  void dispose() {
    _url.dispose();
    super.dispose();
  }

  Future<void> _start() async {
    setState(() {
      _log.clear();
      _result = null;
    });
    final result = await Okyc.start(
      context,
      OkycConfig(sessionUrl: _url.text.trim()),
      onEvent: (e) => setState(() => _log.add('${e.type.name} ${e.payload.isEmpty ? '' : e.payload}')),
    );
    setState(() {
      _result = switch (result) {
        OkycCompleted(:final sessionId, :final status) => 'Completed · $status · $sessionId\n'
            'Fetch the verified result on your server: GET /v1/sessions/$sessionId',
        OkycCancelled(:final sessionId) => 'Cancelled${sessionId == null ? '' : ' · $sessionId'}',
        OkycFailed(:final code, :final message) => 'Failed · $code · $message',
      };
    });
  }

  @override
  Widget build(BuildContext context) {
    final t = Theme.of(context);
    return Scaffold(
      appBar: AppBar(title: const Text('OKYC Flutter example')),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          TextField(
            key: const Key('session-url'),
            controller: _url,
            decoration: const InputDecoration(
              labelText: 'Session URL',
              hintText: 'https://verify.okyc.stream/s/ses_…#t=st_…',
              border: OutlineInputBorder(),
            ),
            keyboardType: TextInputType.url,
            autocorrect: false,
            maxLines: 3,
            minLines: 1,
          ),
          const SizedBox(height: 12),
          FilledButton.icon(
            key: const Key('start'),
            onPressed: _start,
            icon: const Icon(Icons.verified_user_outlined),
            label: const Text('Start verification'),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 8),
            child: Text(
              'Paste the url your server got from POST /v1/sessions. Never put a secret API key in an app.',
              style: t.textTheme.bodySmall?.copyWith(color: t.colorScheme.onSurfaceVariant),
            ),
          ),
          if (_result != null) ...[
            const SizedBox(height: 24),
            Text('Result', style: t.textTheme.titleSmall),
            const SizedBox(height: 4),
            SelectableText(_result!, key: const Key('result')),
          ],
          if (_log.isNotEmpty) ...[
            const SizedBox(height: 16),
            Text('Events', style: t.textTheme.titleSmall),
            const SizedBox(height: 4),
            for (final line in _log) Text(line, style: t.textTheme.bodySmall?.copyWith(fontFamily: 'monospace')),
          ],
        ],
      ),
    );
  }
}
0
likes
140
points
441
downloads

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

OKYC identity verification for Flutter: the hosted KYC/KYB flow in a secure, full-screen WebView with native permissions, file picking and results.

Homepage

Topics

#kyc #identity-verification #webview #okyc

License

MIT (license)

Dependencies

flutter, url_launcher, webview_flutter, webview_flutter_android, webview_flutter_wkwebview

More

Packages that depend on okyc_flutter

Packages that implement okyc_flutter