Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

prompting users

prompting users

flutter package for prompting users to upgrade when there is a newer version of the app in the store.

when a newer app version is availabe in the app store, a simple alert prompt widget or card is displayed. with today’s modern app stores, there is little need to persuade users to upgrade because most of them are already using the auto upgrade feature. however, there may be times when an app needs to be updated more quickly than usual, and nagging a user to upgrade will entice the upgrade sooner. also, with flutter supporting more than just android and ios app stores in the future, it will become more likely that users on other app stores need to be nagged about upgrading.

the ui comes in two flavors: alert or card. the upgradealert class is used to display the popup alert prompt, and the upgradecard class is used to display the inline material design card.

the text displayed in the upgrader package is localized in english and spanish, and supports customization.

alert example

prompting users

just wrap your body widget in the upgradealert widget, and it will handle the rest.

import 'package:flutter/material.dart';
import 'package:upgrader/upgrader.dart';

void main() => runapp(myapp());

class myapp extends statelesswidget {
  myapp({
    key key,
  }) : super(key: key);

  @override
  widget build(buildcontext context) {
    return materialapp(
      title: 'upgrader example',
      home: scaffold(
          appbar: appbar(
            title: text('upgrader example'),
          ),
          body: upgradealert(
            child: center(child: text('checking...')),
          )
      ),
    );
  }
}

screenshot of alert

prompting users

prompting users

card example

prompting users

just return an upgradecard widget in your build method and a material design card will be displayed
when an update is detected. the widget will have width and height of 0.0 when no update is detected.

return container(
        margin: edgeinsets.fromltrb(12.0, 0.0, 12.0, 0.0),
        child: upgradecard());

screenshot of card

prompting users

example2

customization

prompting users

the upgradealert widget can be customized by setting parameters in the constructor of the
upgradealert widget.

  • appcastconfig: the appcast configuration, defaults to null
  • client: an http client that can be replaced for mock testing, defaults to null
  • daysuntilalertagain: days until alerting user again, which defaults to 3
  • debugdisplayalways: always force the upgrade to be available, defaults to false
  • debugdisplayonce: display the upgrade at least once once, defaults to false
  • debuglogging: display logging statements, which defaults to false
  • messages: optional localized messages used for display in upgrader
  • onignore: called when the ignore button is tapped, defaults to null
  • onlater: called when the later button is tapped, defaults to null
  • onupdate: called when the update button is tapped, defaults to null
  • showignore: hide or show ignore button on dialog, which defaults to true
  • showlater: hide or show later button on dialog, which defaults to true
  • candismissdialog: can alert dialog be dismissed on tap outside of the alert dialog, which defaults to false (not used by alert card)
  • countrycode: the country code that will override the system locale, which defaults to null (ios only)
  • minappversion: the minimum app version supported by this app. earlier versions of this app will be forced to update to the current version. defaults to null.

limitations

prompting users

these widgets work on both android and ios. when running on ios the app store will provide the
latest app version and will display the prompt at the appropriate times.

on android, this widget
does nothing as there is no easy way to query the google play store for metadata about an app.
without the metadata, the widget cannot compare the app version with the latest play store version.
it will not disrupt the widget tree and can be
included in an android without any issues.

there is now an appcast that can be used for android and ios to remotely configure the
latest app version.

appcast

prompting users

the class appcast, in this flutter package, is used by the upgrader widgets
to download app details from an appcast,
based on the sparkle framework by andy matuschak.
you can read the sparkle documentation here:
https://sparkle-project.org/documentation/publishing/.

an appcast is an rss feed with one channel that has a collection of items that each describe
one app version. the appcast will decscribe each app version and will provide the latest app
version to upgrader that indicates when an upgrade should be recommended.

the appcast must be hosted on a server that can be reached by everyone from the app. the appcast
xml file can be autogenerated during the release process, or just manually updated after a release
is available on the app store.

the appcast class can be used stand alone or as part of upgrader.

appcast example

prompting users

final appcast = appcast();
final items = await appcast.parseappcastitemsfromuri('https://raw.githubusercontent.com/larryaasen/upgrader/master/test/testappcast.xml');
final bestitem = appcast.bestitem();

appcast sample file

prompting users

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
    <channel>
        <title>debt now app - appcast</title>
        <item>
            <title>version 1.15.0</title>
            <description>desc</description>
            <pubdate>sun, 30 dec 2018 12:00:00 +0000</pubdate>
            <enclosure url="https://play.google.com/store/apps/details?id=com.moonwink.treasury" sparkle:version="1.15.0" sparkle:os="android" />
        </item>
    </channel>
</rss>

combined android & ios example

prompting users

@override
widget build(buildcontext context) {
  // on android, setup the appcast.
  // on ios, the default behavior will be to use the app store version of
  // the app, so update the bundle identifier in example/ios/runner with a
  // valid identifier already in the app store.
  final appcasturl = 'https://www.mydomain.com/myappcast.xml';
  final cfg = appcastconfiguration(url: appcasturl, supportedos: ['android']);

  return materialapp(
    title: 'upgrader example',
    home: scaffold(
        appbar: appbar(
          title: text('upgrader example'),
        ),
        body: upgradealert(
          appcastconfig: cfg,
          debuglogging: true,
          child: center(child: text('checking...')),
        )),
  );
}

customizing the display

prompting users

the strings displayed in upgrader can be customzied by extending the upgradermessages class
to provide custom values.

as an example, to replace the ignore button with a custom value, first create a new
class that extends upgradermessages, and override the buttontitleignore function. next,
when calling upgradealert (or upgradecard), add the paramter messages with an instance
of your extended class. here is an example:

class myupgradermessages extends upgradermessages {
  @override
  string get buttontitleignore => 'my ignore';
}

upgradealert(messages: myupgradermessages());

language localization

the strings displayed in upgrader are already localized in various languages. new languages will be
supported in the future with minor updates.

languages supported:

  • english (en)
  • arabic (ar)
  • french (fr)
  • portuguese (pt)
  • spanish (es)
  • polish (pl)

the upgrader package can be supplied with additional languages in your code by extending the upgradermessages class
to provide custom values.

as an example, to add the spanish (es) language (which is already provided), first create a new
class that extends upgradermessages, and override the message function. next, add a string for
each of the messages. finally, when calling upgradealert (or upgradecard), add the paramter messages with an instance
of your extended class. here is an example:

class myspanishmessages extends upgradermessages {
  /// override the message function to provide custom language localization.
  @override
  string message(upgradermessage messagekey) {
    if (languagecode == 'es') {
      switch (messagekey) {
        case upgradermessage.body:
          return 'es a new version of {{appname}} is available!';
        case upgradermessage.buttontitleignore:
          return 'es ignore';
        case upgradermessage.buttontitlelater:
          return 'es later';
        case upgradermessage.buttontitleupdate:
          return 'es update now';
        case upgradermessage.prompt:
          return 'es want to update?';
        case upgradermessage.title:
          return 'es update app?';
      }
    }
    // messages that are not provided above can still use the default values.
    return super.message(messagekey);
  }
}

upgradealert(messages: myspanishmessages());

you can even force the upgrade package to use a specific language, instead of the
system language on the device. just pass the language code to an instance of
upgradermessages when displaying the alert or card. here is an example:

upgradealert(messages: upgradermessages(code: 'es'));

itunes search api

there is a class in this flutter package used by the upgrader widgets to download app details
from the
itunes search api.
the class itunessearchapi can be used standalone to query itunes for app details.

itunessearchapi example

final itunes = itunessearchapi();
final resultsfuture = itunes.lookupbybundleid('com.google.maps');
resultsfuture.then((results) {
    print('results: $results');
});

results

results--1-

command line app

there is a command line app used to display the results from itunes search. the code is located in
bin/itunes_lookup.dart, and can be run from the command line like this:

$ dart itunes_lookup.dart bundleid=com.google.maps

results:

upgrader: download: https://itunes.apple.com/lookup?bundleid=com.google.maps
upgrader: response statuscode: 200
itunes_lookup bundleid: com.google.maps
itunes_lookup trackviewurl: https://apps.apple.com/us/app/google-maps-transit-food/id585027354?uo=4
itunes_lookup version: 5.31
itunes_lookup all results:
{resultcount: 1, results: 
...

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.