Flutter安全认证插件yubikit_flutter的使用
Flutter安全认证插件yubikit_flutter的使用
关于
yubikit_flutter
是一个围绕 YubiKit iOS 和 YubiKit Android SDK 的 Flutter 封装库。目前仅支持 PIV(Personal Identity Verification)和原始智能卡功能。
若需要 OpenPGP 相关的功能,请添加 Yubikit OpenPGP 插件。
更多详细信息可以查看 YubiKit iOS 和 YubiKit Android 项目。
使用示例
以下是一个完整的示例,展示如何在 Flutter 中使用 yubikit_flutter
插件来实现 PIV 和 OpenPGP 功能。
完整代码示例
// 导入必要的包
import 'package:flutter/material.dart';
import 'package:yubikit_flutter_example/openpgp.dart'; // OpenPGP 页面
import 'package:yubikit_flutter_example/piv.dart'; // PIV 页面
void main() {
runApp(const MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
// 当前选中的选项索引
int _selectedIndex = 0;
// 可供切换的页面列表
static const List<Widget> _widgetOptions = [
OpenPGPPage(), // OpenPGP 页面
PivPage(), // PIV 页面
];
// 底部导航栏点击事件处理函数
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Yubikit'), // 应用标题
),
body: _widgetOptions.elementAt(_selectedIndex), // 显示当前选中的页面
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex, // 当前选中的底部导航项
selectedItemColor: Colors.amber[800], // 选中项颜色
onTap: _onItemTapped, // 点击事件回调
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home), // 图标
label: 'PGP', // 标签
),
BottomNavigationBarItem(
icon: Icon(Icons.account_balance), // 图标
label: 'PIV', // 标签
),
],
),
);
}
}
1 回复