How to check if in app update code is working

2.3k Views Asked by At

I have a live app on playstore and I want to use in_app_update package in flutter to check for app updates and update the app on user's phone. I have the following code which runs the app update in the background and shows a spinner until the updates are done. Before publishing this new code, I want to be sure if it works. In other words, how can I test if

 InAppUpdate.performImmediateUpdate()

will work when there is an update?

Does anyone have an idea how can I be sure if this code works before publishing it to playstore?

import 'package:in_app_update/in_app_update.dart';

Future<void> main() async {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  var _isLoading;
  var appUpdate;
  void didChangeDependencies() async {
    setState(() {
      _isLoading = true;
      });
    await InAppUpdate.checkForUpdate().then((info) {
      print('Starting app updates'); 
       AppUpdateInfo _updateInfo = info;
      appUpdate = _updateInfo.updateAvailable;
      print('App update aye? ' + appUpdate.toString());
      if(appUpdate)
       InAppUpdate.performImmediateUpdate()
                            .catchError((e) => print(e.toString()));
     print('Finishing app updates'); 
    }).catchError((e) {
      print(e.toString());
    });
    super.didChangeDependencies();
    print('isloadign to false'); 
      setState(() {
        // Get image url
      _isLoading = false;
      });
  }

  @override
  Widget build(BuildContext context) {
    return !(_isLoading)?MultiProvider(
      providers: [
       ChangeNotifierProvider(
          create: (_) => Auth(),
        ),
        child: Consumer<Auth>(builder: (ctx, auth, _) => 
          MaterialApp(     
        title: 'MyApp', 
       home: ProductDetailScreen(),
        routes: {
          ProductDetailScreen.routeName:(ctx) => ProductDetailScreen(),
        }
      ),
        ) 
    ):Center(child:Loading());
  }
}
2

There are 2 best solutions below

0
On

You can try launching a release in closed testing track feature on Google Play. So it will be signed & published to Google Play but will be available only to chosen users. You can create a user, add yourself to the closed testing track.

As for the other point of view - This plugin wraps the official Android API, hence I recommend reading Android documentation to check if there is some information about testing it.

0
On

The way I approach such kind of a problem is,

  • Making the version in your pubspec.yaml file lower than the one you have on Playstore or AppStore. That way, the app detects that there is a published update and tries to run the update functionality from your build app.

Say, if on PlayStore or AppStore your app version is 1.0.0, then in your pubspec.yaml file you will revert to anything lower than1.0.0 like 0.0.7. And Voila!