Flutter : How to show update dialog for new version available for android and IOS Flutter

Viewed 33

I need to show update alert dialog for Android and IOS when ever new version available. I tried different packages

  1. package_info_plus -> https://pub.dev/packages/package_info_plus
try {
      isUpdateAvailable = false;
      final uri = Uri.https("play.google.com", "/store/apps/details", {"id": "${_packageInfo.packageName}"});
      final response = await http.get(uri);
      // print("response is ${response.body}");
      final document = parse(response.body);
      print(1);
      final additionalInfoElements = document.getElementsByClassName('hAyfc');
      print("additionalInfoElements $additionalInfoElements");
      print(2);
      final versionElement = additionalInfoElements.firstWhere((elm) {
        print(elm.querySelector('.BgcNfc')?.text);
        return elm.querySelector('.BgcNfc')?.text == 'Current Version';
      });
      print(3);

      final storeVersion = versionElement.querySelector('.htlgb')?.text ?? "";

      print("storeVersion is $storeVersion");
      print("_packageInfo.version is ${_packageInfo.version}");

      if (_packageInfo.version != storeVersion) {
        isUpdateAvailable = true;
        if (!mounted) return;
        setState(() {});
      }
    } on Exception catch (exception) {
      print("exception is $exception");
    } catch (err) {
      print("err is ${err}");
    }

I/flutter (13572): 1
I/flutter (13572): additionalInfoElements []
I/flutter (13572): 2
I/flutter (13572): err is Bad state: No element
  1. in_app_update -> https://pub.dev/packages/in_app_update
InAppUpdate.checkForUpdate().then((info) {
      setState(() {
        _updateInfo = info;
      });
    }).catchError((e) {
      print("E is $e");
      MPSnackBar.failMsg(context, e.toString());
    });

I/PlayCore(13854): UID: [10211]  PID: [13854] AppUpdateService : requestUpdateInfo(com.metalpower.metaCloud)
I/PlayCore(13854): UID: [10211]  PID: [13854] AppUpdateService : Initiate binding to the service.
I/PlayCore(13854): UID: [10211]  PID: [13854] AppUpdateService : Failed to bind to the service.
I/flutter (13854): E is PlatformException(TASK_FAILURE, Failed to bind to the service., null, null)
  1. new_version -> https://pub.dev/packages/new_version
final newVersion = NewVersion(
      iOSId: 'IOS_ID',
      androidId: 'android_id',
    );

    final status = await newVersion.getVersionStatus();
    if (status != null) {
      debugPrint(status.releaseNotes);
      debugPrint(status.appStoreLink);
      debugPrint(status.localVersion);
      debugPrint(status.storeVersion);
      debugPrint(status.canUpdate.toString());
      newVersion.showUpdateDialog(
        context: context,
        versionStatus: status,
        dialogTitle: 'Custom Title',
        dialogText: 'Custom Text',
      );
    }

E/flutter (13854): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 1
E/flutter (13854): #0      List.[] (dart:core-patch/growable_array.dart:264:36)
E/flutter (13854): #1      NewVersion._getAndroidStoreVersion
package:new_version/new_version.dart:188
E/flutter (13854): <asynchronous suspension>
E/flutter (13854): #2      _SplashScreenUIState.checkStatus
package:metal_power_mobile/…/splash_screen/splash_screen_ui.dart:259
E/flutter (13854): <asynchronous suspension>
  1. native_updater -> https://pub.dev/packages/native_updater
  2. upgrader -> https://pub.dev/packages/upgrader

tried upgrader and appCast.xml added in git hub

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
    <channel>
        <title>Help Code TJCODE- Appcast</title>
        <item>
            <title>Version 3.15.0</title>
            <description>desc</description>
            <pubDate>Tue, 08 Oct 2022 12:00:00 +0000</pubDate>
            <enclosure url="https://play.google.com/store/apps/details?id=appId" sparkle:version="1.0.0" sparkle:os="android" />
        </item>
    </channel>
</rss>

but it is also not working

I'm struck from past 4 days. Can any one help me how to do implement app update dialog

Thanks.

0 Answers
Related