eimzo_flutter 2.4.1
eimzo_flutter: ^2.4.1 copied to clipboard
Flutter plugin wrapping the official E-IMZO Mobile SDK for Uzbekistan electronic signatures: PFX, QR, ID card and USB token keys, signing through the YT gateway.
example/lib/main.dart
import 'dart:convert';
import 'package:eimzo_flutter/eimzo_flutter.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'E-IMZO Demo',
theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.indigo),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
/// A sign request the way an app makes one: the site's id, the document's
/// id and the hash come from the app's own backend — here, a document
/// captured from E-IMZO during QA — and the plugin makes the link. Never an
/// `eimzo://` link taken from outside: that scheme is the E-IMZO app's.
static final _signLink = EimzoSignLink.create(
siteId: '1a47',
documentId: '59282737',
hash: '518b091cc3878831103872e422ec71d2e6ee501e255dce3290af02042edfcd69',
);
/// The same config every time: iOS uses the last one `init` was given.
static const _config = EimzoConfig(environment: EimzoEnvironment.dev);
final _eimzo = EimzoFlutter.instance;
/// The Keys API's last answer, as the SDK gave it.
String? _json;
/// The keys from the last `getKeys()`, and the one picked for `sign()`.
List<Map<String, dynamic>> _keys = const [];
String? _keyId;
/// «Kalitlar API»: lists the keys the user has added in the SDK's UI.
/// Only for an integrator YT has given the permission; otherwise the JSON
/// says `api_not_allowed`.
Future<void> _listKeys() async {
if (!await _eimzo.init(config: _config)) return;
final json = await _eimzo.getKeys();
final reply = jsonDecode(json) as Map<String, dynamic>;
final keys = reply['status'] == 'ok'
? (reply['keys'] as List).cast<Map<String, dynamic>>()
: const <Map<String, dynamic>>[];
if (!mounted) return;
setState(() {
_json = json;
_keys = keys;
if (!keys.any((k) => k['id'] == _keyId)) {
_keyId = keys.isEmpty ? null : keys.first['id'] as String;
}
});
}
/// «Kalitlar API»: signs [_signLink] with the picked key in the SDK's own
/// sheet. The answer says how it ended; the signed document itself goes
/// from E-IMZO to the site's backend.
Future<void> _signWithKey(String keyId) async {
final json = await _eimzo.sign(keyId: keyId, deepLink: _signLink);
if (!mounted) return;
setState(() => _json = json);
}
/// `validTo` is how an app tells an expired key; the list includes them.
static String _label(Map<String, dynamic> key) {
final validTo = key['validTo'] as String?;
final expired = DateTime.tryParse(validTo ?? '')?.isBefore(DateTime.now()) ?? false;
return '${key['name']} · ${validTo ?? '—'}${expired ? ' (muddati o\'tgan)' : ''}';
}
@override
Widget build(BuildContext context) {
final keyId = _keyId;
final json = _json;
return Scaffold(
appBar: AppBar(title: const Text('E-IMZO Flutter')),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
ElevatedButton.icon(
icon: const Icon(Icons.open_in_new),
label: const Text('Open E-IMZO native UI'),
onPressed: () async {
final allowed = await _eimzo.init(config: _config);
if (!allowed) return;
await _eimzo.openSignUi();
},
),
const SizedBox(height: 8),
ElevatedButton.icon(
icon: const Icon(Icons.qr_code_2),
label: const Text('Open with a sign request'),
onPressed: () => _eimzo.openSignUi(deepLink: _signLink),
),
const Divider(height: 32),
Text('Kalitlar API', style: Theme.of(context).textTheme.titleMedium),
const SizedBox(height: 8),
ElevatedButton.icon(
icon: const Icon(Icons.key),
label: const Text('Kalitlar ro\'yxati'),
onPressed: _listKeys,
),
if (_keys.isNotEmpty) ...[
const SizedBox(height: 8),
DropdownButton<String>(
isExpanded: true,
value: keyId,
items: [
for (final key in _keys)
DropdownMenuItem(
value: key['id'] as String,
child: Text(_label(key), overflow: TextOverflow.ellipsis),
),
],
onChanged: (id) => setState(() => _keyId = id),
),
],
const SizedBox(height: 8),
ElevatedButton.icon(
icon: const Icon(Icons.draw),
label: const Text('Tanlangan kalit bilan imzolash'),
onPressed: keyId == null ? null : () => _signWithKey(keyId),
),
if (json != null) ...[
const SizedBox(height: 16),
SelectableText(json, style: const TextStyle(fontFamily: 'monospace')),
],
],
),
);
}
}