sotaid_pluging 0.0.1+1 copy "sotaid_pluging: ^0.0.1+1" to clipboard
sotaid_pluging: ^0.0.1+1 copied to clipboard

A Flutter plugin for integrating SotaBoost's identity verification service into Flutter applications

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sotaid_pluging/sotaid_pluging.dart';
import 'package:sotaid_pluging/verification_flow.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'SotaID Plugin Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'SotaID Plugin Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final SotaidPluging _plugin = SotaidPluging();
  String _platformVersion = 'Unknown';
  List<Map<String, dynamic>> _countries = [];
  bool _isLoading = false;
  String _bearerToken = 'sotaboost'; // Test token for sandbox

  @override
  void initState() {
    super.initState();
    // Initialize plugin with bearer token (defaults to sandbox mode)
    _plugin.initialize(bearerToken: _bearerToken);
    _initPlatformState();
  }

  Future<void> _initPlatformState() async {
    String? platformVersion;
    try {
      platformVersion = await _plugin.getPlatformVersion();
    } catch (e) {
      platformVersion = 'Failed to get platform version: $e';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion ?? 'Unknown';
    });
  }

  Future<void> _loadCountries() async {
    setState(() {
      _isLoading = true;
    });

    try {
      final countries = await _plugin.getCountries();
      setState(() {
        _countries = countries;
        _isLoading = false;
      });
      
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Successfully loaded ${countries.length} countries')),
      );
    } catch (e) {
      setState(() {
        _isLoading = false;
      });
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('Error loading countries: $e'),
          backgroundColor: Colors.red,
        ),
      );
    }
  }

  Future<void> _startVerification() async {
    try {
      setState(() {
        _isLoading = true;
      });

      final sessionData = await _plugin.createVerificationSession({
        'user_id': 'example_user_${DateTime.now().millisecondsSinceEpoch}',
        'created_at': DateTime.now().toIso8601String(),
      });
      
      setState(() {
        _isLoading = false;
      });

      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('Session created successfully: ${sessionData['id']}'),
          backgroundColor: Colors.green,
        ),
      );
    } catch (e) {
      setState(() {
        _isLoading = false;
      });
      
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('Error creating session: $e'),
          backgroundColor: Colors.red,
        ),
      );
    }
  }

  void _showVerificationFlow() {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (context) => Scaffold(
          appBar: AppBar(
            title: Text('SotaID Verification'),
            backgroundColor: Colors.transparent,
            elevation: 0,
          ),
          body: SotaIdVerificationFlow(
            bearerToken: _bearerToken,
            onVerificationComplete: (response) {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(
                  content: Text('Verification completed: ${response.status}'),
                  backgroundColor: Colors.green,
                ),
              );
              Navigator.of(context).pop();
            },
            onError: (error) {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(
                  content: Text('Verification error: $error'),
                  backgroundColor: Colors.red,
                ),
              );
            },
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'Platform Version',
                      style: Theme.of(context).textTheme.titleMedium,
                    ),
                    const SizedBox(height: 8),
                    Text(_platformVersion),
                  ],
                ),
              ),
            ),
            const SizedBox(height: 16),
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'SotaBoost API',
                      style: Theme.of(context).textTheme.titleMedium,
                    ),
                    const SizedBox(height: 8),
                    Text(
                      'Bearer Token: $_bearerToken',
                      style: TextStyle(
                        fontFamily: 'monospace',
                        fontSize: 12,
                        color: Colors.grey[600],
                      ),
                    ),
                    const SizedBox(height: 16),
                    Row(
                      children: [
                        Expanded(
                          child: ElevatedButton(
                            onPressed: _isLoading ? null : _loadCountries,
                            child: Text(_isLoading ? 'Loading...' : 'Load Countries'),
                          ),
                        ),
                        const SizedBox(width: 8),
                        Expanded(
                          child: ElevatedButton(
                            onPressed: _isLoading ? null : _startVerification,
                            child: Text('Create Session'),
                          ),
                        ),
                      ],
                    ),
                    const SizedBox(height: 16),
                    SizedBox(
                      width: double.infinity,
                      child: ElevatedButton(
                        onPressed: _showVerificationFlow,
                        style: ElevatedButton.styleFrom(
                          backgroundColor: Colors.blue,
                          foregroundColor: Colors.white,
                        ),
                        child: Text('Start Verification Flow'),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            if (_countries.isNotEmpty) ...[
              const SizedBox(height: 16),
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        'Available Countries (${_countries.length})',
                        style: Theme.of(context).textTheme.titleMedium,
                      ),
                      const SizedBox(height: 8),
                      Container(
                        height: 200,
                        child: ListView.builder(
                          itemCount: _countries.length,
                          itemBuilder: (context, index) {
                            final country = _countries[index];
                            return ListTile(
                              leading: CircleAvatar(
                                child: Text(country['code'] ?? ''),
                              ),
                              title: Text(country['name'] ?? 'Unknown'),
                              subtitle: Text('Documents: ${(country['allowed_docs'] as List?)?.join(', ') ?? 'None'}'),
                            );
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
0
likes
0
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for integrating SotaBoost's identity verification service into Flutter applications

License

unknown (license)

Dependencies

dropdown_button2, flutter, http, image_picker, plugin_platform_interface

More

Packages that depend on sotaid_pluging

Packages that implement sotaid_pluging