sima 1.0.1+12 copy "sima: ^1.0.1+12" to clipboard
sima: ^1.0.1+12 copied to clipboard

Flutter plugin for SIMA digital signature integration.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: SimaExamplePage(),
    );
  }
}

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

  @override
  State<SimaExamplePage> createState() => _SimaExamplePageState();
}

class _SimaExamplePageState extends State<SimaExamplePage> {
  bool _isLoading = false;
  String _resultText = 'Hazırdır';

  // ---------------------------------------------------------------------------
  // ✅ SAFE VARIANT (RECOMMENDED)
  // ---------------------------------------------------------------------------
  Future<void> _startSimaSafe() async {
    _setLoading('SIMA açılır (Safe)...');

    try {
      final challenge = Sima.createChallenge();
      final signature = await _mockSign(challenge.toBase64());

      final response = await Sima.loginSafe(
        clientId: 'YOUR_CLIENT_ID',
        returnScheme: 'your-app-scheme',
        serviceName: 'SIMA Example',
        logoPath: 'assets/logo.png',
        challenge: challenge,
        signature: signature,
      );

      _handleResponse(response);
    } catch (e) {
      _setResult('Xəta baş verdi: $e');
    } finally {
      _stopLoading();
    }
  }

  // ---------------------------------------------------------------------------
  // ⚠️ LEGACY VARIANT (DEMO ONLY)
  // ---------------------------------------------------------------------------
  Future<void> _startSimaLegacy() async {
    _setLoading('SIMA açılır (Legacy)...');

    try {
      final response = await Sima.login(
        clientId: 'YOUR_CLIENT_ID',
        clientMasterKey: 'YOUR_MASTER_KEY',
        returnScheme: 'your-app-scheme',
        serviceName: 'SIMA Example',
        logoPath: 'assets/logo.png',
      );

      _handleResponse(response);
    } catch (e) {
      _setResult('Xəta baş verdi: $e');
    } finally {
      _stopLoading();
    }
  }

  // ---------------------------------------------------------------------------
  // 🧠 HELPERS
  // ---------------------------------------------------------------------------
  Future<String> _mockSign(String challengeBase64) async {
    await Future.delayed(const Duration(milliseconds: 400));
    return 'MOCK_SIGNATURE_FROM_BACKEND';
  }

  void _handleResponse(SimaResponse? response) {
    if (response == null) {
      _setResult('Əməliyyat ləğv edildi');
      return;
    }

    if (!response.isSuccess) {
      _setResult('Xəta: ${response.message ?? 'unknown'}');
      return;
    }

    _setResult('''
✅ UĞURLU

Request ID: ${response.requestId}
Signature: ${response.signature}
Certificate: ${response.certificate}
Challenge: ${response.challenge}
''');
  }

  void _setLoading(String text) {
    setState(() {
      _isLoading = true;
      _resultText = text;
    });
  }

  void _stopLoading() {
    setState(() => _isLoading = false);
  }

  void _setResult(String text) {
    setState(() => _resultText = text);
  }

  // ---------------------------------------------------------------------------
  // 🧱 UI
  // ---------------------------------------------------------------------------
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('SIMA Plugin Example')),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            ElevatedButton(
              onPressed: _isLoading ? null : _startSimaSafe,
              child: const Text('Sign with SIMA (Safe)'),
            ),
            const SizedBox(height: 8),
            ElevatedButton(
              style: ElevatedButton.styleFrom(backgroundColor: Colors.orange),
              onPressed: _isLoading ? null : _startSimaLegacy,
              child: const Text('Sign with SIMA (Legacy – Demo Only)'),
            ),
            const SizedBox(height: 24),
            Expanded(
              child: SingleChildScrollView(
                child: SelectableText(
                  _resultText,
                  style: const TextStyle(fontSize: 14),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
56
downloads

Publisher

verified publishersec.az

Weekly Downloads

Flutter plugin for SIMA digital signature integration.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

crypto, flutter

More

Packages that depend on sima

Packages that implement sima