Flutter身份验证插件shuftipro_onsite_sdk_beta的使用
Flutter身份验证插件shuftipro_onsite_sdk_beta的使用
在本示例中,我们将展示如何在Flutter应用中使用shuftipro_onsite_sdk_beta
插件进行身份验证。以下是详细的步骤和代码示例。
初始化插件
首先,确保你已经在pubspec.yaml
文件中添加了shuftipro_onsite_sdk_beta
依赖项:
dependencies:
shuftipro_onsite_sdk_beta: ^版本号
然后运行flutter pub get
来安装该插件。
示例代码
以下是一个完整的示例,展示了如何初始化并使用shuftipro_onsite_sdk_beta
插件。
main.dart
import 'package:flutter/material.dart';
import 'package:shuftipro_onsite_sdk_beta/shuftipro_onsite_sdk_beta.dart';
import 'dart:convert';
// 替换为你的客户端ID和密钥
String clientId = ""; // 进入客户端ID
String secretKey = ""; // 进入密钥
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
scaffoldBackgroundColor: Colors.white,
fontFamily: 'OpenSans'),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
[@override](/user/override)
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// 配置认证对象
var authObject = {
"auth_type": "basic_auth",
"client_id": clientId,
"secret_key": secretKey,
};
// 创建payload对象
Map<String, Object> createdPayload = {
"country": "",
"language": "",
"email": "",
"callback_url": "",
"redirect_url": "",
"show_consent": 1,
"show_privacy_policy": 1,
"verification_mode": "image_only",
"face": {
"proof": "",
},
"document": {
"supported_types": [
"passport",
"id_card",
"driving_license",
"credit_or_debit_card",
],
"name": {
"first_name": "",
"last_name": "",
"middle_name": "",
},
"dob": "",
"document_number": "",
"expiry_date": "",
"issue_date": "",
"gender": "",
"backside_proof_required": "0",
},
};
// 配置对象
Map<String, Object> configObj = {
"base_url": "api.shuftipro.com",
"show_requirement_page": true,
};
/*
* This function sends call to the Shuftipro's flutter plugin
* and receives the response in a variable
*/
Future<void> initPlatformState() async {
String response = "";
try {
response = await ShuftiproSdk.sendRequest(
authObject: authObject,
createdPayload: createdPayload,
configObject: configObj);
var object = jsonDecode(response);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(object.toString()),
));
print(object.toString());
print(object["event"].toString());
} catch (e) {
print(e);
}
if (!mounted) return;
}
/*
* Click listener to start the SDK flow
*/
void continueFun() {
var v = DateTime.now();
var reference = "package_sample_Flutter_$v";
createdPayload["reference"] = reference;
initPlatformState();
}
/*
* UI of demo application
*/
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: Container(
margin: const EdgeInsets.all(10.0),
child: OutlinedButton(
onPressed: continueFun,
style: OutlinedButton.styleFrom(backgroundColor: Colors.blueAccent),
child: Container(
alignment: Alignment.center,
child: const Text(
"继续",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'OpenSans',
),
),
),
),
),
));
}
}
更多关于Flutter身份验证插件shuftipro_onsite_sdk_beta的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复