【问题标题】:new_version package in flutter returns RangeError (index): Invalid value: Valid value range is empty: 1Flutter中的new_version包返回RangeError(index):无效值:有效值范围为空:1
【发布时间】:2022-11-03 09:16:42
【问题描述】:

我在颤振中使用 new_vesrion ^0.3.1 包来显示警报对话框,如果颤振应用程序商店有新版本可用,则显示更新应用程序,但我得到以下书面异常:

[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 1
E/flutter ( 5988): #0      List.[] (dart:core-patch/growable_array.dart:264:36)
E/flutter ( 5988): #1      NewVersion._getAndroidStoreVersion (package:new_version/new_version.dart:195:26)
E/flutter ( 5988): <asynchronous suspension>
E/flutter ( 5988): #2      _SplashScreenState._checkVersion (package:cardicare/appScreens/Splash_Screen.dart:124:20)

下面我给出了我编写的代码,用于显示 Flutter 应用程序新更新的警报对话框:

void _checkVersion() async
  {
    
     final newVersion = NewVersion
     (
      androidId: androidAppId,
      iOSId: iOSAppId
     );
     
    final status = await newVersion.getVersionStatus();
    if(status!=null)
    { 
      if(status.canUpdate)
      {
        newVersion.showUpdateDialog
          (
            context: context, 
            versionStatus: status,
            dialogTitle: "Update!!!",
            //dismissButtonText: "Skip",
            dialogText: "Please update your app from "+"${status.localVersion}"+ " to "+ "${status.storeVersion}",
            allowDismissal: false,
            dismissAction: () 
            {
              SystemNavigator.pop();  
            },
            updateButtonText: "Let's Update"
          );    
      }
       print("app version on Device "+"${status.localVersion}");  
       print("app version on store "+"${status.storeVersion}");
    }     
}

_checkVersion() 方法在启动画面的 initState() 中被调用。 所以请帮我解决这个问题。

【问题讨论】:

    标签: flutter package


    【解决方案1】:

    我想我找到了问题,如果您将 GET 发送到 [https://play.google.com/store/apps/details?id=APP_ID&hl=en],我会查看库并与 google 的返回结果进行比较

    我认为谷歌已经改变了他们的回报,在版本返回 ds:4 脚本之前,但现在它返回到 ds:5

    如果您将第 183 行从 new_version.dart 更改为

    (elm) => elm.text.contains('key: 'ds:5''),
    

    错误消失了,我认为他们必须更新库

    @编辑

    我已经从 GitHub 下载文件 new_version 并粘贴到我的项目中,进行一些更改并且工作正常

    【讨论】:

    • 感谢分享解决方案。使用您的解决方案后,它现在正在工作。再次感谢您的快速回复。
    • 好抓哥哥
    【解决方案2】:

    如果您的应用尚未发布,则它一定会引发错误

    尝试添加一个try catch,如果失败则不显示弹出窗口

    String storeVersion = "";
    try{
      storeVersion = status.storeVersion;
    }catch(e){}
    

    【讨论】:

      猜你喜欢
      • 2020-11-01
      • 2020-04-19
      • 2020-09-22
      • 1970-01-01
      • 2020-06-24
      • 2021-10-06
      • 2021-11-13
      • 2022-08-17
      • 1970-01-01
      相关资源
      最近更新 更多