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

Issue

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?

Solution

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…

Answered By – Maadhav Sharma

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *