【问题标题】:Unable to open UPI apps from Android and IOS in flutter无法从 Android 和 IOS 中打开 UPI 应用程序
【发布时间】:2022-11-13 14:32:53
【问题描述】:

我正在尝试添加此 URL 启动器。但我越来越upi://pay?pa=dinesh@dlanzer&pn=Dinesh&am=1&tn=hello&cu=INR 的组件名称为空错误。对于 SMS 和电子邮件工作正常。

【问题讨论】:

  • 你能测试链接吗

标签: flutter dart url flutter-layout upi


【解决方案1】:

首先你必须在flutter中使用URL启动器插件

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.

  # url launcher
  url_launcher: ^6.1.4

现在我制作 UPI Launcher 助手功能 我可以在多个应用程序中启动我的 upi,例如 paytm、phonePe、Gpay、BHIM、Whatsapp Pay 等。

我在这里通过 upiID,(必填) 姓名(可选) 金额(可选) 备注(可选)

您仍然可以根据需要传递更多数据

显示辅助函数

paymentUrlLaunch({
  required String upi,
  String? amount,
  String? name,
  String? note,
}) async {
  String nameUrl = (name != null && name.isNotEmpty) ? "&pn=$name" : "";
  String amountUrl = (amount != null && amount.isNotEmpty) ? "&am=$amount" : "";
  String noteUrl = (note != null && note.isNotEmpty) ? "&tn=$note" : "";
  String link = 'upi://pay?pa=$upi' +
      nameUrl +
      amountUrl +
      noteUrl +
      "&cu=INR" ;

  Uri url = Uri.parse(link);

  var willLaunch = await canLaunchUrl(url);  // from url launcher plugIN
  if (willLaunch) {
    launchUrl(url);
  } else {
    upiToaster(msg: 'Url not launch'); // if failed notified by toaster
  }

 
}

请注意 这里使用 TextFormField 和控制器通过验证传递了 UPIID、名称、金额和注释

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    相关资源
    最近更新 更多