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

11,854

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...

Share:
11,854
Md Azharuddin
Author by

Md Azharuddin

I like to play with Flutter and know a bit of AI.

Updated on June 27, 2022

Comments

  • Md Azharuddin
    Md Azharuddin almost 2 years

    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?

  • Md Azharuddin
    Md Azharuddin almost 4 years
    Thanks for your suggestion but now I am facing issue using in_app_update. I have edited the question. Can you help, please?
  • Maadhav Sharma
    Maadhav Sharma almost 4 years
    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.