How to force users to update app from play store in Flutter using in_app_update
Asked Answered
B

3

16

I want the users of my app to always have the latest version. If they don't have the latest version, it should download the latest version from play store first as shown in the image.

Forced Update

I found a package called Upgrader but this just gives a prompt. It is not linked to play store as shown in image.

Edit

As suggested by Maadhav Sharma, now I am using the in_app_update package but it says no update available.

This is my code:

....

class _TnPState extends State<TnP> {
  ThemeBloc _themeBloc;
  FirebaseMessaging _firebaseMessaging;
  NotificationBloc _notificationBloc;
  String _test;

  @override
  void initState() {
    _themeBloc = ThemeBloc();
    _firebaseMessaging = FirebaseMessaging();
    _notificationBloc = NotificationBloc();
    _firebaseMessaging.configure(
      onMessage: (notification) async => _notificationBloc.yes(),
      onResume: (notification) async => _notificationBloc.yes(),
      onLaunch: (notification) async => _notificationBloc.yes(),
    );
    checkForUpdate();
    super.initState();
  }

  Future<void> checkForUpdate() async {
    InAppUpdate.checkForUpdate().then((info) {
      String display = info.toString();
      setState((){
        _test = display;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<AppTheme>(
      stream: _themeBloc.themeStream,
      initialData: AppTheme.Light,
      builder: (context, AsyncSnapshot<AppTheme> snapshot) {
        return MaterialApp(
          title: 'TnP',
          debugShowCheckedModeBanner: false,
          theme: appThemeData[snapshot.data],
          home: _test==null ?
                Container() : 
                InAppUpdateScreen(display: _test),//SplashScreen(),
        );
      },
    );
  }
}

InAppUpdateScreen just displays the text.
App in play store shows update is available:
App in play store


But the app which is an older version installed via playstore shows no update:
No update in app


Any idea how to solve this?

Borghese answered 1/6, 2020 at 9:24 Comment(4)
I don't know how but next day it started working! Maybe some problem from playstore I guess.Borghese
can you please share the whole code for it? I am also troubled with the force update app. It is giving me no update available.Greenquist
It won't detect update unless you see update available in My apps and games section.Borghese
It won't detect update if you do not install production version of the app from Play Store. Other similar packages also acting similarly. Installing from Android Studio, command line or thru internal testing will not work, only production version from Play Store needed.Worshipful
F
13

There is a package for what you want:

https://pub.dev/packages/in_app_update
enter image description here

Android
This plugin integrates the official Android APIs to perform in app updated that were released in 2019: https://developer.android.com/guide/app-bundle/in-app-updates

iOS
iOS does not offer such a functionality. You might want to look into e.g. https://pub.dev/packages/upgrader. If you call the methods above on a iOS device you'll run into a not-implemented exception.

Thanks...

Favorite answered 1/6, 2020 at 9:34 Comment(2)
Thanks for your suggestion but now I am facing issue using in_app_update. I have edited the question. Can you help, please?Borghese
I don't know abt that but maybe its due to the internal beta version. Anyway acc. to me U should ask the question as an issue in the plugin's repo.Favorite
A
2

You can use this package
https://pub.dev/packages/upgrader

Wrap your whole widget in UpgradeAlert widget like this ->

Scaffold(
          appBar: AppBar(title: Text('Upgrader Example')),
          body: UpgradeAlert(
            child: Center(child: Text('Your widget is here')),
          )),

if an update available

On Ios style On Android Style

Asinine answered 22/5, 2022 at 9:29 Comment(0)
T
1

Might not be the actual answer for the question but if someone is looking for an easy to integrate built in solution, which works for both Android, iOS and is language, framework agnostic. if you are looking for an easy to integrate built in solution. You can use App Upgrade https://appupgrade.dev/ service to force update your mobile apps.

  • Create new version entry for your app version that you want to update in the app upgrade service and select whether you want to force it or just want to let users know that new version is available.

App Upgrade

  • Integrate your app with App Upgrade using available SDK. Official SDK are available for React Native, Flutter, Expo, Android and iOS(Swift). The SDK will take care of the rest. Whenever you want to force upgrade a version just create a version entry in app upgrade dashboard.

App Upgrade Popup

  • You can also integrate using API. Just call the appupgrade api from your app with the required details such as your app version, platform, environment and app name.
  • The API will return you the details.. that this app needs to be updated or not.
  • Based on the response you can show popup in your app.You can call this API when app starts or periodically to check for the update. You can even provide a custom message. API response:

App Upgrade API Response

See the response has force update true. So handle in the app by showing popup.

App Upgrade Popup

You can find the complete user documentation here. https://appupgrade.dev/docs

Thanks.

Tisiphone answered 6/4, 2022 at 20:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.