GithubHelp home page GithubHelp logo

ofload / native_updater Goto Github PK

View Code? Open in Web Editor NEW
55.0 3.0 46.0 1.25 MB

Flutter package to embed native in-app updater

License: MIT License

Dart 87.86% Kotlin 0.83% Ruby 8.53% Swift 2.54% Objective-C 0.24%
flutter flutter-plugin in-app-updates

native_updater's Introduction

native_updater

pub package

Flutter package for prompting users to update with a native dialog whether using the app store version or any version at the user's discretion.

When a latest app version is available via user defined logic, a simple alert prompt widget is displayed. With today's modern app stores, there is little need to persuade users to update because most of them are already using the auto update feature. However, there may be times when an app needs to be updated more quickly than usual, and nagging a user to update will entice the update sooner.

The UI comes in two flavors: Material Design for Android and Cupertino for iOS. The UpdateMaterialAlert widget is used to display the native Android alert prompt, and the UpdateCupertinoAlert widget is used to display the native iOS alert prompt.

Installation via GitHub (for test only)

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.3

  # Add this inside pubspec.yaml
  native_updater:
    git: https://github.com/loadsmileau/native_updater

Setup

Android

Already good to go.

iOS

To be able to show your App Name in the Cupertino Alert Dialog, add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

<key>CFBundleDisplayName</key>
<string>YOUR APP NAME</string>

Usage

Just add this code whenever you want to display the update alert, and it will handle the rest.

NativeUpdater.displayUpdateAlert(
  context,
  forceUpdate: true,
);

Or with the optional parameters to customize the alert.

NativeUpdater.displayUpdateAlert(
  context,
  forceUpdate: true,
  appStoreUrl: '<Your App Store URL>',
  playStoreUrl: '<Your Play Store URL>',
  iOSDescription: '<Your iOS Description>',
  iOSUpdateButtonLabel: '<Your iOS Update Button Label>',
  iOSCloseButtonLabel: '<Your iOS Close Button Label>',
  iOSIgnoreButtonLabel: '<Your iOS Ignore Button Label>',
  iOSAlertTitle: '<Your Dialog Title>',
);

Parameters Explanation

Required Parameters

context is the location in the tree where this widget builds.

forceUpdate is to tell whether the alert is forcing an update or not. Set to true if you are forcing an update. Set to false if you are giving an option to update later.

Optional Parameters

appStoreUrl is to launch your App Store URL if you're developing for iOS. Follow this link on how to find your App Store URL.

playStoreUrl is to launch your Play Store URL if you're developing for Android. Follow this link on how to find your Play Store URL.

iOSDescription is to use your custom alert description on UpdateCupertinoAlert. The default is <App Name> requires that you update to the latest version. You cannot use this app until it is updated. or <App Name> recommends that you update to the latest version. You can keep using this app while downloading the update.

iOSUpdateButtonLabel is used to set your custom Update Button Label on UpdateCupertinoAlert. The default is Update.

iOSCloseButtonLabel is used to set your custom Close Button Label onUpdateCupertinoAlert. The default is Close App.

iOSIgnoreButtonLabel is used to set your custom Ignore Button Label onUpdateCupertinoAlert. The default is Later.

iOSAlertTitle is used to set your custom Dialog Title onUpdateCupertinoAlert. The default is Update Available.

Full Example

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'native_updater example',
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  void initState() {
    super.initState();
    checkVersion();
  }

  Future<void> checkVersion() async {
    /// For example: You got status code of 412 from the
    /// response of HTTP request.
    /// Let's say the statusCode 412 requires you to force update
    int statusCode = 412;

    /// This could be kept in our local
    int localVersion = 9;

    /// This could get from the API
    int serverLatestVersion = 10;

    Future.delayed(Duration.zero, () {
      if (statusCode == 412) {
        NativeUpdater.displayUpdateAlert(
          context,
          forceUpdate: true,
          appStoreUrl: '<Your App Store URL>',
          playStoreUrl: '<Your Play Store URL>',
          iOSDescription: '<Your iOS description>',
          iOSUpdateButtonLabel: 'Upgrade',
          iOSCloseButtonLabel: 'Exit',
        );
      } else if (serverLatestVersion > localVersion) {
        NativeUpdater.displayUpdateAlert(
          context,
          forceUpdate: false,
          appStoreUrl: '<Your App Store URL>',
          playStoreUrl: '<Your Play Store URL>',
          iOSDescription: '<Your description>',
          iOSUpdateButtonLabel: 'Upgrade',
          iOSIgnoreButtonLabel: 'Next Time',
        );
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Your App'),
      ),
      body: Center(
        child: Text('Testing...'),
      ),
    );
  }
}

Screenshots of Material Alert

An example of a flexible update flow

image

An example of an immediate update flow

image

Screenshots of Cupertino Alert

Force Update Can Update Later
image image

native_updater's People

Contributors

10peter10 avatar hari-om-888 avatar jeffryhermanto avatar milhomem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

native_updater's Issues

Support for the iOS?

Hi,

Can we use this package for the ios platform as well?

Thanks for the help in advance.

Force update does not really force an update.

Users can easily dismiss the dialog box.
Now since this is a native window, you may not have the ability to change the UI.
Although be any chance is it possible to notify the user's choice by a callback?

Dialog not shown when App on Playstore

I'm very appreciate your work for in app update.
But one thing I notice that update dialog not shown when an app is already on play store even the version number and code is different.
I used latest native_updater version 0.1.0
Please look into this.

Null check operator used on a null value

_CastError: Null check operator used on a null value
File "native_updater.dart", line 79, in NativeUpdater._showCupertinoAlertDialog
File "native_updater.dart", line 58, in NativeUpdater.displayUpdateAlert

Why is playStoreUrl removed?

Error: No named parameter with the name 'playStoreUrl'.

If I go and look at your latest PR there I see that you completely removed this prop.
Nothing is written about it, just deleted.

Error while compiling

/flutter/.pub-cache/hosted/pub.dartlang.org/in_app_update-2.0.0/android/src/main/kotlin/de/ffuf/in_app_update/InAppUpdatePlugin.kt: (226, 26): Type mismatch: inferred type is String? but String was expected

FAILURE: Build failed with an exception.

how get http statusCode?

Hi, in example you describe that I need to get http status code by a requisition. You would send us a example? Or send to us a link thet document this process?

/// For example: You got status code of 412 from the /// response of HTTP request. /// Let's say the statusCode 412 requires you to force update int statusCode = 412;

thanks

NativeUpdater.displayUpdateAlert default call update does not work

Using it like this:
NativeUpdater.displayUpdateAlert(
context,
forceUpdate: true,
);

It displays the alert popup box but clicking update button does not affect anything. Tested with different iOS versions on physical devices and full production AppStore versions.

Add support for checking for versions

It would be awesome if the library could also support a basic update check, using the "standard" APIs, i.e. google play and the iTunes store. To support this, the following would have to be done.

enum UpdateLevel { skip, optional, required }

NativeUpdater.checkForUpdates(
  BuildContext context, {
  UpdateLevel Function(int, int) androidCompareVersion,  // compare version code aka. build number
  UpdateLevel Function(String, String) iosCompareVersion,  // compare version string
  // other parameters from displayUpdateAlert, except forceUpdate, which is replaced by the UpdateLevel result
});

We need two methods for comparing, because on android, the version code / build number is used by google play, while on iOS the actual public version string is used.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.