digified_flutter_plugin 0.0.17 copy "digified_flutter_plugin: ^0.0.17" to clipboard
digified_flutter_plugin: ^0.0.17 copied to clipboard

Flutter plugin for Digified's Arabic eKYC and eContract SDKs. Provides native flows for identity verification and electronic contract signing with updated Android integration (FlutterActivity + Hilt) [...]

example/lib/main.dart

import 'package:digified_flutter_plugin/digified_flutter_plugin.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MainApp());
}

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

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  Locale _locale = const Locale('en');

  String t(String en, String ar) => _locale.languageCode == 'ar' ? ar : en;

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

  Future<void> _initSdk() async {
    // Call SDK initialization helpers after plugins are registered.
    try {
      await DigifiedFlutterPlugin.setLoggingEnabled(true);
    } catch (e) {
      // Safe to ignore in example if plugin isn't registered yet
      print('setLoggingEnabled failed (plugin not ready?): $e');
    }

    // Retry setTheme a few times if MissingPluginException occurs very early
    const retries = 5;
    var attempt = 0;
    while (attempt < retries) {
      try {
        await DigifiedFlutterPlugin.setTheme(
          lightModeTextColor: "#000000",
          lightModeBackgroundColor: "#FFFFFF",
          lightModeButtonTextColor: "#FFFFFF",
          lightModeButtonBackgroundColor: "#0066FF",
          darkModeTextColor: "#FFFFFF",
          darkModeBackgroundColor: "#1C1B1D",
          darkModeButtonTextColor: "#FFFFFF",
          darkModeButtonBackgroundColor: "#0088FF",
        );
        break; // success
      } catch (e) {
        print('setTheme attempt ${attempt + 1} failed: $e');
        attempt += 1;
        await Future.delayed(const Duration(milliseconds: 200));
      }
    }

    if (attempt == retries) {
      print('setTheme failed after $retries attempts');
    }
  }

  void _toggleLanguage() async {
    final newLang = _locale.languageCode == 'ar' ? 'en' : 'ar';
    try {
      await DigifiedFlutterPlugin.setLanguage(newLang);
      setState(() {
        _locale = Locale(newLang);
      });
    } catch (e) {
      print('Failed to set language: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      locale: _locale,
      supportedLocales: const [Locale('en'), Locale('ar')],
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      // Fallback resolution: if a delegate doesn't support the requested locale,
      // fall back to the first supported locale (English) to avoid runtime errors
      localeResolutionCallback: (locale, supportedLocales) {
        if (locale == null) return supportedLocales.first;
        for (var supported in supportedLocales) {
          if (supported.languageCode == locale.languageCode) return supported;
        }
        return supportedLocales.first;
      },
      home: Scaffold(
        appBar: AppBar(
          title: Text(t('Digified Demo', 'عرض ديجيفايد')),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () async {
                  try {
                    final ekycSessionId = await DigifiedFlutterPlugin.presentEKYC(
                      apiKey: "digified-otp-extract-match",
                      baseUrl: "https://ekyc-preprod.digified.dev",
                    );
                    print("eKYC completed. Session ID: $ekycSessionId");
                  } on PlatformException catch (e) {
                    print("eKYC failed: ${e.message}");
                  } catch (e) {
                    print("eKYC error: $e");
                  }
                },
                child: Text(t('Launch eKYC', 'بدء التحقق')),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: () async {
                  try {
                    await DigifiedFlutterPlugin.presentEContract(
                      apiKey: "your_api_key",
                      baseUrl: "your_base_url",
                      faceMatchingApiKey: "your_face_matching_api_key",
                      faceMatchingBaseUrl: "your_face_matching_base_url",
                      eKYCSessionID: "your_ekyc_session_id",
                      templateVersionID: "your_template_version_id",
                      variables: {
                        "key1": "value1",
                        "key2": "value2",
                      },
                    );
                    print("eContract completed successfully");
                  } on PlatformException catch (e) {
                    print("eContract failed: ${e.message}");
                  }
                },
                child: Text(t('Launch eContract', 'بدء العقد الإلكتروني')),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: _toggleLanguage,
                child: Text(t('Switch to Arabic', 'التبديل إلى الإنجليزية')),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: () async {
                  try {
                    await DigifiedFlutterPlugin.openAppSettings();
                  } catch (e) {
                    print('Failed to open app settings: $e');
                  }
                },
                child: Text(t('Open App Settings', 'فتح إعدادات التطبيق')),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
0
points
779
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin for Digified's Arabic eKYC and eContract SDKs. Provides native flows for identity verification and electronic contract signing with updated Android integration (FlutterActivity + Hilt) and iOS 16+ support.

Homepage
Repository
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter

More

Packages that depend on digified_flutter_plugin

Packages that implement digified_flutter_plugin