Flutter统一支付接口插件get_upi的使用
Flutter统一支付接口插件get_upi的使用
标题
Flutter统一支付接口插件get_upi的使用
内容
-
Getting Started
- 这个Flutter插件是Android和iOS原生SDK的包装。
-
Installation
- 在
pubspec.yaml
文件中添加以下依赖:get_upi: ^0.0.4
- 在
-
Requirements
- 添加以下内容到应用的manifest文件中:
- 如果使用此包进行UPI授权,请将主机设置为
mandate
,否则设置为pay
。
- 如果使用此包进行UPI授权,请将主机设置为
- 添加以下内容到应用的manifest文件中:
-
Usage
-
导入包:
import 'package:get_upp/get_upp.dart';
-
获取所有已安装的UPI应用程序(对于Android):
List<UpiObject> upiAppsList = []; Future<void> getUpi() async { if (Platform.isAndroid) { var value = await GetUPI.apps(); upiAppsListAndroid = value.data; } else if (Platform.isIOS) { var valueIos = await GetUPI.iosApps(); upiAppsList.clear(); upiAppsList = valueIos; } setState(() {}); }
-
使用native intent打开UPI应用程序:
GetUPI.openNativeIntent(url: 'pass the upi string');
-
从
upiAppsList
中打开UPI应用程序:GetUPI.launch( package: upiApp.packageName, url: 'pass the upi string', );
-
示例代码
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_upp/get_upp.dart';
void main() {
runApp(
MaterialApp(
theme: ThemeData(useMaterial3: true),
home: const MyApp(),
),
);
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
[@override](/user/override)
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List upiAppsList = [];
List<UpiObject> upiAppsListAndroid = [];
MethodChannel methodChannel = const MethodChannel("get_upp");
[@override](/user/override)
void initState() {
super.initState();
}
Future<void> getUpp() async {
if (Platform.isAndroid) {
var value = await GetUPI.apps();
uppAppsListAndroid = value.data;
} else if (Platform.isIOS) {
var valueIos = await GetUPI.iosApps();
upiAppsList.clear();
upiAppsList = valueIos;
}
setState(() {});
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
if (Platform.isAndroid) {
GetUPI.openNativeIntent(
url: 'your mandate url',
);
} else if (Platform.isIOS) {
getUpp().then((_) {
GetUPI.showUpiSheet(
context,
upiAppsList: upiAppsList,
mandateUrl: "your mandate url",
);
});
}
},
child: const Text("Native Intent"),
),
),
);
}
}
更多关于Flutter统一支付接口插件get_upi的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复