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

Flutter package for integrating Meon DigiLocker APIs with dynamic form fields and validation

example/lib/main.dart

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

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

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

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

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // Replace these with your actual credentials
  final String companyName = 'democapital'; // Replace with your company name
  final String secretToken = 'cy7Kw2rWqdzVo2KPxlU0ymd9uRQKPSsb'; // Replace with your secret token

  bool _showDigiLocker = false;
  SendEntireDataResponse? _verificationResult;
  String? _errorMessage;

  void _startVerification() {
    setState(() {
      _showDigiLocker = true;
      _verificationResult = null;
      _errorMessage = null;
    });
  }

  void _handleSuccess(SendEntireDataResponse data) {
    setState(() {
      _showDigiLocker = false;
      _verificationResult = data;
      _errorMessage = null;
    });

    // Show success dialog
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: const Text('Verification Successful!'),
        content: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              if (data.data.name != null) ...[
                Text('Name: ${data.data.name}'),
                const SizedBox(height: 8),
              ],
              if (data.data.aadharNo != null) ...[
                Text('Aadhaar Number: ${data.data.aadharNo}'),
                const SizedBox(height: 8),
              ],
              if (data.data.panNumber != null) ...[
                Text('PAN Number: ${data.data.panNumber}'),
                const SizedBox(height: 8),
              ],
              if (data.data.dob != null) ...[
                Text('Date of Birth: ${data.data.dob}'),
                const SizedBox(height: 8),
              ],
              Text('Verification Code: ${data.code}'),
              Text('Status: ${data.status}'),
            ],
          ),
        ),
        actions: [
          TextButton(
            onPressed: () => Navigator.of(context).pop(),
            child: const Text('OK'),
          ),
        ],
      ),
    );
  }

  void _handleError(String error) {
    setState(() {
      _showDigiLocker = false;
      _errorMessage = error;
      _verificationResult = null;
    });

    // Show error dialog
    showDialog(
      context: context,
      builder: (context) => AlertDialog(
        title: const Text('Verification Failed'),
        content: Text(error),
        actions: [
          TextButton(
            onPressed: () => Navigator.of(context).pop(),
            child: const Text('OK'),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Meon DigiLocker SDK Example'),
        backgroundColor: Theme.of(context).colorScheme.primary,
        foregroundColor: Theme.of(context).colorScheme.onPrimary,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // Header
            const Text(
              'DigiLocker Document Verification',
              style: TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
            const SizedBox(height: 8),
            Text(
              'This example demonstrates how to use the Meon DigiLocker SDK '
              'for Flutter to verify documents through DigiLocker.',
              style: TextStyle(
                color: Colors.grey[600],
                height: 1.5,
              ),
            ),
            const SizedBox(height: 24),

            // Credentials info
            Card(
              child: Padding(
                padding: const EdgeInsets.all(16),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Text(
                      'Current Configuration',
                      style: TextStyle(
                        fontSize: 18,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    const SizedBox(height: 12),
                    Text('Company Name: $companyName'),
                    const SizedBox(height: 4),
                    Text('Secret Token: ${secretToken.substring(0, 10)}...'),
                    const SizedBox(height: 12),
                    Container(
                      padding: const EdgeInsets.all(8),
                      decoration: BoxDecoration(
                        color: Colors.orange.shade50,
                        border: Border.all(color: Colors.orange.shade200),
                        borderRadius: BorderRadius.circular(4),
                      ),
                      child: Text(
                        '⚠️ Note: This is a demo configuration. '
                        'Replace with your actual credentials for production use.',
                        style: TextStyle(
                          color: Colors.orange.shade800,
                          fontSize: 12,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),

            const SizedBox(height: 24),

            // Start verification button
            if (!_showDigiLocker) ...[
              SizedBox(
                width: double.infinity,
                child: ElevatedButton(
                  onPressed: _startVerification,
                  style: ElevatedButton.styleFrom(
                    padding: const EdgeInsets.symmetric(vertical: 16),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(8),
                    ),
                  ),
                  child: const Text(
                    'Start Document Verification',
                    style: TextStyle(fontSize: 16),
                  ),
                ),
              ),
            ],

            // Error display
            if (_errorMessage != null && !_showDigiLocker) ...[
              const SizedBox(height: 16),
              Container(
                padding: const EdgeInsets.all(12),
                decoration: BoxDecoration(
                  color: Colors.red.shade50,
                  border: Border.all(color: Colors.red.shade200),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Row(
                  children: [
                    Icon(Icons.error, color: Colors.red.shade600),
                    const SizedBox(width: 8),
                    Expanded(
                      child: Text(
                        _errorMessage!,
                        style: TextStyle(color: Colors.red.shade600),
                      ),
                    ),
                  ],
                ),
              ),
            ],

            // Verification result
            if (_verificationResult != null) ...[
              const SizedBox(height: 16),
              Card(
                color: Colors.green.shade50,
                child: Padding(
                  padding: const EdgeInsets.all(16),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Icon(Icons.check_circle, color: Colors.green.shade600),
                          const SizedBox(width: 8),
                          const Text(
                            'Verification Completed Successfully!',
                            style: TextStyle(
                              fontSize: 16,
                              fontWeight: FontWeight.w500,
                              color: Colors.green,
                            ),
                          ),
                        ],
                      ),
                      const SizedBox(height: 12),
                      Text(
                        'Response Code: ${_verificationResult!.code}',
                        style: const TextStyle(fontWeight: FontWeight.w500),
                      ),
                      Text('Status: ${_verificationResult!.status}'),
                      if (_verificationResult!.data.name != null) ...[
                        const SizedBox(height: 8),
                        Text('Name: ${_verificationResult!.data.name}'),
                      ],
                      if (_verificationResult!.data.aadharNo != null) ...[
                        Text('Aadhaar: ${_verificationResult!.data.aadharNo}'),
                      ],
                      if (_verificationResult!.data.panNumber != null) ...[
                        Text('PAN: ${_verificationResult!.data.panNumber}'),
                      ],
                    ],
                  ),
                ),
              ),
            ],
          ],
        ),
      ),

      // DigiLocker Form (shown when verification is started)
      bottomSheet: _showDigiLocker
          ? Container(
              height: MediaQuery.of(context).size.height * 0.9,
              decoration: const BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
              ),
              child: DigilockerForm(
                companyName: companyName,
                secretToken: secretToken,
                onSuccess: _handleSuccess,
                onError: _handleError,
                primaryColor: Theme.of(context).colorScheme.primary,
              ),
            )
          : null,
    );
  }
}
0
likes
0
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter package for integrating Meon DigiLocker APIs with dynamic form fields and validation

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, http, provider, webview_flutter

More

Packages that depend on flutter_meon_digilocker