《Flutter入门疑难杂症》in_app_purchase重复购买无法结束上一个购买的问题

报错内容:
PlatformException(storekit_duplicate_product_object, There is a pending transaction for the same product identifier. Please either wait for it to be finished or finish it manually using completePurchase to avoid edge cases., {applicationUsername: 1325712443552333826, requestData: null, quantity: 1, productIdentifier: yitianhuiyuanqntest, simulatesAskToBuyInSandbox: null}, null)

报错原因:
上一个购买 还没收到回调,就直接结束了界面,关闭了监听.
这个问题困扰了好久,最后才找到解决方案:初始化的时候结束掉上个购买.

解决方案:

  //初始化appStore信息,询商品列表
  Future<bool> initStoreInfo(List<String> _kProductIds) async {
   
    L.v(
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 ScreenUtil 类,可以用于 Flutter 屏幕适配: ```dart import 'package:flutter/material.dart'; class ScreenUtil { static late double _screenWidth; static late double _screenHeight; static late double _pixelRatio; static late double _statusBarHeight; static late double _bottomBarHeight; static late double _textScaleFactor; static void init(BuildContext context) { MediaQueryData mediaQuery = MediaQuery.of(context); _screenWidth = mediaQuery.size.width; _screenHeight = mediaQuery.size.height; _pixelRatio = mediaQuery.devicePixelRatio; _statusBarHeight = mediaQuery.padding.top; _bottomBarHeight = mediaQuery.padding.bottom; _textScaleFactor = mediaQuery.textScaleFactor; } static double get screenWidth => _screenWidth; static double get screenHeight => _screenHeight; static double get pixelRatio => _pixelRatio; static double get statusBarHeight => _statusBarHeight; static double get bottomBarHeight => _bottomBarHeight; static double get textScaleFactor => _textScaleFactor; static double setWidth(double width) => width * _screenWidth / 375; static double setHeight(double height) => height * _screenHeight / 667; static double setSp(double fontSize) => fontSize * _textScaleFactor; static double setBorderRadius(double radius) => radius * _pixelRatio; } ``` 使用方法: 在 MaterialApp 的 build 方法中调用 ScreenUtil.init(context),初始化 ScreenUtil 类。 ```dart class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { ScreenUtil.init(context); return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } } ``` 在布局中使用 ScreenUtil.setWidth、ScreenUtil.setHeight 和 ScreenUtil.setSp 方法来适配宽度、高度和字体大小。 ```dart Container( width: ScreenUtil.setWidth(100), height: ScreenUtil.setHeight(100), margin: EdgeInsets.only(top: ScreenUtil.setHeight(20)), padding: EdgeInsets.symmetric(horizontal: ScreenUtil.setWidth(20)), decoration: BoxDecoration( borderRadius: BorderRadius.circular(ScreenUtil.setBorderRadius(10)), color: Colors.grey[200], ), child: Text( 'Hello, World!', style: TextStyle(fontSize: ScreenUtil.setSp(16)), ), ), ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值