flutter - 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
它发生在一些插件上,而不仅仅是这个。所以我发现问题可能不在于这个特定的插件,而是不同的东西?
解决方案
有一个插件可用于执行此操作,称为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.'
}`
你就完成了。
推荐阅读
- android - Play() 只能由用户手势启动
- javascript - Typeahead 不建议第二个选项
- react-native - 如何在 Reacti-Native 中插入换行符
- c# - 更新自定义控件上的属性单击
- python-2.7 - 如何使用 python 2.7 标准应用引擎从 gcs 提供图像?
- ios - 如何在 swiftlint 配置文件中禁用字符限制
- javascript - nodejs没有连接到mongodb云服务器
- javascript - Redux 错误:您当前正在使用 NODE_ENV 之外的缩小代码
- arraylist - ArrayList 的深拷贝
- vue.js - 如果未填写强制输入,则在提交时提醒用户