Update new version is not working in flutter

Viewed 465

I have a flutter app which has an update button. This is used to update when new version is available in play store. It works fine until few days before. But now it is not working. It only shows a notification when user has installed the same version otherwise an error will be thrown.

> 2022-07-04 12:01:39.072 27969-28023/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Bad state: No element
    #0      ListMixin.firstWhere (dart:collection/list.dart:167)
    #1      NewVersion._getAndroidStoreVersion (package:new_version/new_version.dart:157)
    <asynchronous suspension>
    #2      _SettingsPageState._checkVersion (package:bnews/ui_components/pages/settings_page.dart:196)
    <asynchronous suspension>

So now I cant update my app using this update button. I use new_version flutter package to update. This is the code

      void _checkVersion() async {
   final newVersion = NewVersion(
      androidId: "com.abc.def",
    );
    final status = await newVersion.getVersionStatus();
    newVersion.showUpdateDialog(
      context: context,
      versionStatus: status!,
      dialogTitle: "UPDATE!!!",
      dialogText: "Please update the app from " + "${status.localVersion}" + " to " + "${status.storeVersion}",
      updateButtonText: "Lets update",
    );
  }

I think package not found problem is there. But it works fine until few days before. I have also updated new_version package but still same problem. Is this problem with playstore?

2 Answers

this is a bug check pub.dev new_version issues

for checking if there is a new version, I use upgrader package, just wrap the home of your materialApp and it will handle everything:

home: UpgradeAlert(
                upgrader: Upgrader(
                  showReleaseNotes: false,
                  dialogStyle: UpgradeDialogStyle.cupertino,
                  shouldPopScope: () => true,
                ),
                child: MyHomepage(),
              ),
Related