首页 > 解决方案 > Flutter java.lang.NullPointerException 上集成一些插件

问题描述

有一些插件,例如https://github.com/mrdishant/Paytm-Flutter-Plugin

我正在尝试整合。但我收到此错误:java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on an null object reference

它发生在一些插件上,而不仅仅是这个。所以我发现问题可能不在于这个特定的插件,而是不同的东西?

标签: flutterpaytm

解决方案


有一个插件可用于执行此操作,称为paytmkaro,您可以使用它,但它仅适用于生产密钥。您可以使用它,因为它更易于使用。

在开始将服务器端代码上传到服务器上之前,请不要对用于在 paytm 服务器上生成 txn 令牌的服务器端代码进行任何更改

将最低 sdk 版本更改为 19

只需复制粘贴此代码

` try {
  PaytmResponse paymentResponse = await _paytmKaro.startTransaction(
    url: serverside code url e.g. https://arcane-temple-61754.herokuapp.com/intiateTansection.php,
    mid: your Production merchant id,
    mkey: your merchant key,
    customerId:customer id (must be unique for every customer),
    amount: transection amount,
    orderId: Order Id (Order id must be unique Everytime for every order),
  );

  if(paymentResponse.status=="TXN_SUCCESS"){
    Navigator.push(context, MaterialPageRoute(builder: (context)=>txnSuccessful(paytmResponse: paymentResponse,)));
  }
  else if(paymentResponse.status=="TXN_FAILURE"){
    Navigator.push(context, MaterialPageRoute(builder: (context)=>txnFailed(paytmResponse: paymentResponse,)));
  }
} 
catch(e){
  print(e);
  key.currentState.showSnackBar(SnackBar(content: Text(e.toString())));      // platformVersion = 'Failed to get platform version.'
}`

你就完成了。


推荐阅读