Android Dev

In App Replace – Tips on how to Notify Customers of App Updates in Flutter

Whenever you roll out a brand new model of your software, you need your customers to learn about it. Whether or not you mounted a important bug, added a brand new characteristic, or the appliance simply runs smoother or quicker – they should know.

As software builders, we would like all of our customers to make use of the newest model of our software.

However how can we guarantee that customers are conscious of a brand new model of our software?

The reply to that query is sort of easy: Why not inform them when a brand new model of the appliance is out?

You are able to do this in varied methods:

  • Use a push notification
  • Allow them to know when the appliance is launched

We received’t be coping with push notifications on this article. As a substitute we’ll deal with exhibiting how one can (utilizing a bundle or two) present a dialog to your customers informing them {that a} new model of the appliance is out and the way to cope with the replace.

Wait, Isn’t This Already Included?

You’ll assume that this sort of performance ought to already be included within the trendy cell OS programs. And you’ll be proper – however just for Android.

iOS doesn’t (at the moment) give builders the flexibility to see if there’s a new model of the appliance and notify customers about it. In Android, you have got the In-App Update library that’s a part of the Google Play libraries.

Due to this, and since Flutter helps each platforms, I’m going to go over two distinguished packages that make it easier to deal with model updates to your software:

  1. Upgrader
  2. In App Update

Each can get you the specified outcome, however they fluctuate extensively in how they do it.

Earlier than we begin, it’s essential to know that you will need to have a model of your software that was put in instantly from the Google Play retailer. That is required since each packages depend on Google Play companies and its capacity to confirm the proprietor of the appliance.

When you fail to take action, you will notice the next error when making an attempt to make use of one of many packages:

_Install Error(-10): The app just isn’t owned by any person on this machine. An app is “owned” if it has been acquired from Play. (https://developer.android.com/reference/com/google/android/play/core/set up/mannequin/InstallErrorCode#ERROR_APP_NOTOWNED)

Tips on how to Use The In App Replace Package deal

Proper off the bat you must know that this bundle will solely work on Android. It is because it depends on the in app replace library for its inside workings.

This bundle is principally a wrapper for the Android library. Beneath are its uncovered API strategies:

  • Future<AppUpdateInfo> checkForUpdate(): Checks if there’s an replace obtainable
  • Future<AppUpdateResult> performImmediateUpdate(): Performs an instantaneous replace (full-screen)
  • Future<AppUpdateResult> startFlexibleUpdate(): Begins a versatile replace (background obtain)
  • Future<void> completeFlexibleUpdate(): Really installs an obtainable versatile replace

✋ If you wish to learn extra concerning the variations between an instantaneous replace or a versatile replace, head over here.

Tips on how to Set Up the Package deal

First, add the bundle to your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  in_app_update: ^3.0.0

Then carry out pub get.

Inside your software, the place you propose to carry out the logic to deal with in app updates, add the next import:

import 'bundle:in_app_update/in_app_update.dart';

We’ll first want so as to add logic that checks if our software has an replace. To try this, we are going to use the checkForUpdate methodology. Its return worth is a Future which incorporates details about the supply and progress of an app replace.

We will verify if an replace is out there through the use of the updateAvailability property. If an replace is out there, it would have the worth of UPDATE_AVAILABLE. So, your methodology might appear like this:

InAppUpdate.checkForUpdate().then((updateInfo) {
  if (updateInfo.updateAvailability == UpdateAvailability.updateAvailable) {
      
  }
});

Subsequent, we have to resolve which sort of replace we need to set off – both a versatile or an instantaneous replace.

Going for an instantaneous replace must be reserved for an software replace that’s important on your customers. That will imply a model that fixes a important bug or affords a brand new characteristic.

To begin an instantaneous replace, we are able to use the performImmediateUpdate methodology. This methodology returns a AppUpdateResult enum that allows you to know if the replace was profitable or not.

Earlier than calling this methodology we have to verify if we’re allowed to run an instantaneous replace. We try this by accessing the immediateUpdateAllowed flag on the AppUpdateInfo object.

If we need to set off a versatile replace, we use the startFleixbleUpdate methodology. This runs within the background and just like the fast replace methodology. It additionally returns an AppUpdateResult enum.

If on this situation the replace was profitable, we have to name the completeFlexibleUpdate methodology to put in the replace to our software.

So, if we take a look at the code snippet above and add the logic for the several types of updates, it would appear like this:

InAppUpdate.checkForUpdate().then((updateInfo) {
  if (updateInfo.updateAvailability == UpdateAvailability.updateAvailable) {
      if (updateInfo.immediateUpdateAllowed) {
          
          InAppUpdate.performImmediateUpdate().then((appUpdateResult) {
              if (appUpdateResult == AppUpdateResult.success) {
                
              }
          });
      } else if (updateInfo.flexibleUpdateAllowed) {
        
        InAppUpdate.startFlexibleUpdate().then((appUpdateResult) {
              if (appUpdateResult == AppUpdateResult.success) {
                
                InAppUpdate.completeFlexibleUpdate();
              }
          });
      }
  }
});

Tips on how to Use The Upgrader Package deal

Versus the primary possibility, this one affords an answer for each iOS and Android. It depends on gathering information from the shop and checking it in opposition to the present information from the appliance itself.

As a substitute of getting an API to question the info, this bundle has widgets that carry out the logic below the hood.

Tips on how to Set Up the Package deal

First, add the bundle to your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  upgrader: ^5.0.0

Then carry out pub get.

Inside your software, the place you propose to carry out the logic to deal with in app updates, add the next import:

import 'bundle:upgrader/upgrader.dart';

The principle distinction between these two choices is only a UI one, so decide the one that matches essentially the most for you.

To combine this bundle, you have to to wrap your physique widget with both UpgradeAlert or UpgradeCard. Beneath is an instance:

class MyApp extends StatelessWidget {

  @override
  Widget construct(BuildContext context) {
      return MaterialApp(
        title: applicationName,
        residence: UpgradeAlert(                  
          little one: MainPage(
              key: Key("YOUR_KEY"),
              title: applicationName
          ),
        )
      );
    }
}

If a brand new model of your software is out there within the retailer, you will notice this:

Image

To check issues out, be sure to add this:

await Upgrader.clearSavedSettings()

inside your predominant methodology in your predominant.dart file.

Simply so you might be conscious, there are a ton of configurations which you can set for the Upgrader bundle. I extremely suggest you go and verify these out.

Tips on how to Take a look at the Packages

No matter which bundle you select to work with, it’s essential to know that your logic features correctly.

However how will you try this with out releasing an official model of your software? You should use the interior testing possibility in Google Play Console. By releasing a brand new model of your software to inner testers, it is not going to be a public one and can help you check out the upgrading performance.

Here’s what it’s essential to do:

  1. Log in to your Google Play Console account and head into the appliance you might be engaged on to have the updating logic
  2. Underneath Setup → Inner App Sharing, go to Handle Testers and ensure to permit testers to obtain and set up the shared software. You may both select to take action through hyperlink or by e mail.

Image

  1. Then, go to Testing → Inner Testing and click on on the Create new launch button (prime proper).

Image

  1. Upon getting carried out a launch, you possibly can head again to the principle Inner Testing web page and click on on the Testers tab. There you will notice an inventory containing tester emails (empty proper now). Click on on the blue arrow icon.

Image

  1. On this display you possibly can add your self to be an inner tester (within the Add e mail addresses).

Image

  1. When you find yourself carried out, you possibly can head again to the Inner Testing window. Scroll right down to the underside and you will notice the How testers be part of your check and you will notice a Copy hyperlink button.

Now you can click on the button and ship your self the hyperlink so it is possible for you to to obtain the brand new model of your software.

When you fail to do one of many above steps, the hyperlink generated will result in a not discovered (Error 404) web page:

Image

When you did every little thing efficiently, you will notice the next if you click on on the generated hyperlink:

Image

When you see this error:

_Install Error(-6): The obtain/set up just isn’t allowed, because of the present machine state (e.g. low battery, low disk area, …). (https://developer.android.com/reference/com/google/android/play/core/set up/mannequin/InstallErrorCode#ERROR_INSTALL_NOTALLOWED)

It would imply you might be working your software on an emulated machine and it’s essential to have Google Play Retailer put in on it and be logged in.

Wrapping Up

I wrote this text as a result of I needed to undergo the identical course of when integrating the in app replace bundle with my very own software.

You’re welcome to test it out on the Google Play Store:

Image

And see all the supply code right here:

Thanks for studying!

Source link

Leave a Reply

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

Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker