Flutter卡片展示与管理插件card91_plugin_v2的使用
Flutter卡片展示与管理插件card91_plugin_v2的使用
插件简介
本插件用于根据表单上的验证输入为客户发放卡片。该插件直接与Card91 SDK通信。
特性
- 直接与SDK(安全平台)通信,以发放卡片并创建持卡人。
开始使用
在您的pubspec.yaml
文件中添加插件:
flutter pub add card91_plugin_v2
导入插件
在Dart代码中导入插件:
import 'package:card91_plugin_v2/card91_flutter_library.dart';
使用示例
以下是如何使用插件的示例代码:
class OnBoarding extends StatefulWidget {
const OnBoarding({Key? key}) : super(key: key);
@override
State<OnBoarding> createState() => _OnBoardingState();
}
class _OnBoardingState extends State<OnBoarding> {
final Card91Controller _controller = Card91Controller(); // 创建Card91Controller实例,以便调用SDK所需函数
String env = ""; /// SANDBOX 或 PROD
String templateId = ""; // 模板ID将单独提供
String cardProgramId = ""; // eg.230528190350397ID1CP9723194, 卡片ID
String organizationId = ""; // eg. 230526135544169ID1OID4070270, 组织ID
String uniqueId = ""; // eg. unique, 唯一标识符
String authUrl = ""; // 验证URL,所有应用都需要配置以获取业务令牌
String cardMode = ""; // eg. DIGITAL_ONLY_CARD, 用户想要生成的卡片类型
String customFields = "{\"step1\":[{\"name\":\"fullName\",\"displayText\":\"Full Name\",\"elements\":{\"type\":\"text\",\"defaultValue\":\"\"}},{\"name\":\"mobile\",\"displayText\":\"Mobile No.\",\"elements\":{\"type\":\"text\",\"defaultValue\":\"\"}},{\"name\":\"pan\",\"displayText\":\"PAN\",\"elements\":{\"type\":\"text\",\"defaultValue\":\"\"}},{\"name\":\"nameOnCard\",\"displayText\":\"Name on card\",\"elements\":{\"type\":\"text\",\"defaultValue\":\"\"}}]}";
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
color: Colors.black12,
child: Column(
children: [
IconButton(
onPressed: () {
_controller.callStep!("step2");
},
icon: Icon(
Icons.adb_outlined,
size: 30,
color: AppColors.blackFont,
),
),
const SizedBox(height: 20,),
IssueCard(
env: env,
templateId: templateId,
cardProgramId: cardProgramId,
organizationId: organizationId,
uniqueId: uniqueId,
authUrl: authUrl,
cardMode: cardMode,
customFields: customFields,
card91controller: _controller,
onDataResponse: (String dataResponse) {
print("Data response from SDK-->$dataResponse");
},
),
],
),
),
),
);
}
}
示例步骤JSON参数
{
"step1": [
{
"name": "fullName",
"displayText": "全名",
"elements": {
"type": "text",
"defaultValue": ""
}
},
{
"name": "mobile",
"displayText": "手机号",
"elements": {
"type": "text",
"defaultValue": ""
}
},
{
"name": "pan",
"displayText": "PAN",
"elements": {
"type": "text",
"defaultValue": ""
}
},
{
"name": "nameOnCard",
"displayText": "卡片上的姓名",
"elements": {
"type": "text",
"defaultValue": ""
}
}
]
}
更多关于Flutter卡片展示与管理插件card91_plugin_v2的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复
更多关于Flutter卡片展示与管理插件card91_plugin_v2的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是如何在Flutter项目中使用card91_plugin_v2
插件来展示和管理卡片的示例代码。假设你已经将card91_plugin_v2
插件添加到了你的pubspec.yaml
文件中:
dependencies:
flutter:
sdk: flutter
card91_plugin_v2: ^最新版本号
然后,运行flutter pub get
来安装插件。
以下是一个简单的示例,展示如何使用card91_plugin_v2
插件来创建和管理卡片:
import 'package:flutter/material.dart';
import 'package:card91_plugin_v2/card91_plugin_v2.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Card91 Plugin Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Card91DemoScreen(),
);
}
}
class Card91DemoScreen extends StatefulWidget {
@override
_Card91DemoScreenState createState() => _Card91DemoScreenState();
}
class _Card91DemoScreenState extends State<Card91DemoScreen> {
final List<Map<String, dynamic>> cards = [
{
'title': 'Card 1',
'description': 'This is the first card.',
'imageUrl': 'https://via.placeholder.com/150',
},
{
'title': 'Card 2',
'description': 'This is the second card.',
'imageUrl': 'https://via.placeholder.com/150',
},
// Add more cards as needed
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Card91 Plugin Demo'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Card91Plugin(
cards: cards,
onCardClick: (index) {
// Handle card click event
print('Card clicked: ${cards[index]['title']}');
// You can navigate to a new screen or show a dialog here
},
cardBuilder: (context, index, cardData) {
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.network(
cardData['imageUrl'],
fit: BoxFit.cover,
height: 150,
),
SizedBox(height: 8),
Text(
cardData['title'],
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
SizedBox(height: 4),
Text(cardData['description']),
],
),
);
},
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// Add a new card dynamically
setState(() {
cards.add({
'title': 'New Card',
'description': 'This is a newly added card.',
'imageUrl': 'https://via.placeholder.com/150',
});
});
},
tooltip: 'Add Card',
child: Icon(Icons.add),
),
);
}
}
在这个示例中:
- 我们定义了一个包含卡片数据的列表
cards
,每个卡片数据都是一个包含title
、description
和imageUrl
的Map
。 Card91Plugin
是假设的插件名称(根据card91_plugin_v2
的功能假设的封装),你需要根据实际的插件API进行调整。如果插件没有提供类似的封装,你可能需要使用ListView.builder
或其他方式手动实现。cardBuilder
参数允许我们自定义每个卡片的UI。onCardClick
回调用于处理卡片点击事件。- 浮动操作按钮(FAB)用于动态添加新卡片。
请注意,由于card91_plugin_v2
的具体API和用法可能有所不同,上述代码中的Card91Plugin
和它的参数可能需要根据实际插件的文档进行调整。如果插件没有提供直接的卡片管理功能,你可能需要自行实现卡片的展示和管理逻辑。