Flutter插件flutter_zest的使用_flutter_zest 是一个用于 Flutter 应用程序的插件
Flutter插件flutter_zest的使用_flutter_zest 是一个用于 Flutter 应用程序的插件
flutter_zest
是一个用于 Flutter 应用程序的插件,旨在集成支付功能。通过该插件,开发者可以轻松地在应用中实现支付功能,而无需从头开始编写复杂的支付逻辑。
安装
要安装 flutter_zest
插件,可以在 pubspec.yaml
文件中添加依赖项:
dependencies:
flutter_zest: ${latest_version}
或者直接使用命令行安装:
flutter pub add flutter_zest
使用
以下是一个简单的示例,展示了如何在 Flutter 应用程序中使用 flutter_zest
插件来处理支付操作。
import 'package:flutter/material.dart';
import 'package:flutter_zest/flutter_zest.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Zest(
env: Env.test,
customerEmail: "*****@gmail.com",
description: "A purchase",
onSuccess: (reference) {
print("Success");
},
amountInMinor: "10000",
apiKey: "PK_******-**********************",
onInitFailed: (reason) {
print(reason);
},
),
),
);
}
}
详细说明
- env: 设置为
Env.test
表示使用测试环境。 - customerEmail: 用户的电子邮件地址。
- description: 支付描述,例如 “A purchase”。
- amountInMinor: 支付金额,以最小单位表示(如100应表示为 “10000”)。
- apiKey: API 密钥,用于验证。
- onSuccess: 成功回调函数,当支付成功时调用。
- onInitFailed: 初始化失败回调函数,当插件初始化失败时调用。
注意事项
- 金额以最小单位表示:例如,100应表示为 “10000”。
- 默认货币:默认货币为 NGN(奈拉)。
- 默认环境:默认为生产环境。
- 组件嵌套:组件应嵌套在一个视图组件中,占据其预期的空间。
- 网络权限:确保在
AndroidManifest.xml
中添加了互联网权限。
许可证
flutter_zest
遵循 MIT 许可证。版权属于 Zest Payments Limited 2023。
MIT License
Copyright (c) 2023 Zest Payments Limited
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
更多关于Flutter插件flutter_zest的使用_flutter_zest 是一个用于 Flutter 应用程序的插件的实战教程也可以访问 https://www.itying.com/category-92-b0.html