neo-femo
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Understanding in-app updates in Flutter A few months ago, we mistakenly pushed out a poorly thought out feature that would ruin the experience of the user. Once we realized this we pushed a reverted release immediately. The best thing about this was we were sure the user would be updated almost immediately because of the in-app update flow we implemented. In here lies the importance of in-app updates. Mistakes happen, security issues and slight bugs can be pushed to production. With in-app updates, you can make sure your users are always on the cutting edge with you. So at this point, you're probably wondering what exactly is in-app update. Well then, let's get down to business. ## In-app Updates Now that we've established the importance of app updates, We'll know focus on the implementation. The Android OS provides a feature known as In-app Updates that allows your users to simultaneously update and use your app at the same time. It ensures your users stay on the most current and safest version of your application in the most comfortable way possible. This article will help you accurately setup in-app updates for your application. Let's get you up to speed : ) ### Setup First of all, the plugin of our choice. [in_app_updates](https://pub.dev/packages/in_app_update). Should be added to your pubspec.yaml in the normal convention: ```dart dependencies: in_app_update: ^2.0.0 ``` :::info The latest version is **2.0.0** at the time of writing this article. ::: Secondly, let's look at the folder structure of our application, a simple three-file project ![](https://i.imgur.com/dIStP01.png) ### Use At the top of your preferred dart file, which in this case will be our service class, ```update_service.dart```, import: ```dart import 'package:in_app_update/in_app_update.dart'; ``` It's time for the actual work so let's talk about the flow. When the user opens your application: - You check for any new versions - New version found: - Start preferred method of updating. - Complete update and proceed to the app - Catch and deal with errors that occur during this process - No version found, continue entry into the app. :::info :bulb: The two methods for updating are **Immediate** and **Flexible** updates. We'll come to that later ::: Now that we've established our implementation path, it's about time we write some code right? Okay! #### Check for new version I prefer if this check is done in the ```initState()``` method of the screen that comes up immediately after your splash screen has been shown: ```dart @override void initState() { super.initState(); _startUpdateService(); } //.. Future<void> _startUpdateService() async { try { //This feature is only available on the Android OS //As specified above. if (Platform.isAndroid) { //This runs the code to start the immediate update service await UpdateService.startImmediateUpdate(); } } catch (e) { //Your preferred method of showing the user erros } } ``` In a bit to ensure a degree of decopuling, We'll write the core update logic in a class called ```update_service.dart```, aptly named ```UpdateService``` Once again, make sure to import: ```dart import 'package:in_app_update/in_app_update.dart'; ``` Checking for app update logic: ```dart //For checking updates static Future<AppUpdateInfo?> _checkForUpdate() async { try { return await InAppUpdate.checkForUpdate(); } catch (e) { //Throwing the exception so we can catch it on our UI layer throw e.toString(); } } ``` Here, we're checking for updates via ```InAppUpdate.checkForUpdate()``` and catching any possible errors via the try/catch loop. #### Update if new version exists: Immediate Update As mentioned earlier, we'll be studying immediate updates first. Immediate updates ensures that your user download the update before they even get the chance to use your application. The logic is written below: ```dart static Future<void> checkForImmediateUpdate() async { try { //Call and get the result from the initial function final AppUpdateInfo? info = await _checkForUpdate(); //Because info could be null if (info != null) { if (info.updateAvailability == UpdateAvailability.updateAvailable) { InAppUpdate.performImmediateUpdate(); } } } catch (e) { throw e.toString(); } } ``` Here we're starting an immediate update if there's an update available. This shows a full screen dialog to the user, specifying the size and network options with which to download the update. Screenshot: ![](https://i.imgur.com/yOsVa9J.jpg) #### Update if new version exists: Flexible Update In this update flow, we'll first show the user a dialog specifying whether they want to update their app or not. This initial dialog can be prompted with the code below: ```dart static Future<void> checkForFlexibleUpdate() async { //Here, you'll show the user a dialog asking if the user is wiilling //to update your app while using it try { //We'll check if the there is an actual update final AppUpdateInfo? info = await _checkForUpdate(); //Because info could be null. If info is null, we can safely assume that there is no pending //update if (info != null) { if (info.updateAvailability == UpdateAvailability.updateAvailable) { //The user starts the flexible updates, when it's done we'll ask the user if they want to go ahead with the update or not await InAppUpdate.startFlexibleUpdate(); } } } catch (e) { throw e.toString(); } } ``` After the update is downloaded in the background, the user can then choose to complete the update process. Don't worry about the call flow of these methods, we'll come to that later. For now, let's review the logic to complete the update proces. ```dart static Future<void> completeFlexibleUpdate() async { //Here, the user has downloaded and queued up your new update, it's time to //actually install it! try { await InAppUpdate.completeFlexibleUpdate(); } catch (e) { throw e.toString(); } } ``` Now let's put this usecase in complete code form. Preferrably in the `initState()` method of your `home_screen.dart` screen: ```dart @override void initState() { super.initState(); _startUpdateService(); } Future<void> _startUpdateService() async { try { //This feature is only available on the Android OS //As specified above. if (Platform.isAndroid) { //Here, the user is asked and could decide if they want to start the update or ignore it await UpdateService.checkForFlexibleUpdate(); //After this is done, we'll show a dialog telling the user //that the update is done, and ask them to complete it. //For this case, we'll use a simple dialog to demonstrate this showDialog( context: context, builder: (context) => AlertDialog( content: Text("Your update has been downloaded"), actions: [ TextButton( onPressed: () { UpdateService.completeFlexibleUpdate(); }, child: Text("Finish Update"), ) ] ), ); } } catch (e) { //The user choosing to ignore the flexible update should trigger an exception //Your preferred method of showing the user erros } } ``` In a nutshell - We're showing the user a dialog to tell the user there is an update available and it can be downloaded asynchronously - If the user ignores the dialog, it will fire an exception so you'll know how to handle - The user can also choose to go ahead, in this case when the update is downloaded, the user will be shown a dialog telling them to complete the process - The user can click "Finish Update" to complete the process or the update will happen automatically when next the user fires up the application ### Testing Now that we've figured out how to implement this two types of updates, we have to test them. Now, as you've probably deduced, testing features like this will be tricky and they are. Let's get to it. #### Internal App Sharing Internal app sharing is used to quickly share app bundles using links within your internal team. You can find out more [here.](https://play.google.com/console/about/internalappsharing/) In order to test this feature, you need to upload release versions of your application to your internal app sharing platform. These app bundles must have a difference in **version codes** i.e the version code of one app bundle must be greater than the order. The internal app sharing console can be located with this [link](https://play.google.com/console/u/1/internal-app-sharing/?pli=1). Below is a screenshot of the console: ![](https://i.imgur.com/VcTLjha.jpg) To put this in a clearer way, let me itemize the nuances to be followed: - First of, you need to create release versions, I personally recommend app bundles. You can see details [here](https://flutter.dev/docs/deployment/android). Make sure all your releases are signed with the same keystore - You'll need to generate to signed APKs/App bundles to test it. One APK/App bundle will have a version code greater than the other. For example APK 1 will have the version code: 1 and APK 2 will have the version code: 2. :::info :bulb: You can set the version code by changing the corresponding values in **local.properties** by editing the **flutter.versionCode** field. ::: - Upload both generated APKs/App bundles to your internal app sharing console and they should appear as such: ![](https://i.imgur.com/41Id7Qx.jpg) - Next, you should download the version of the older version via the link in the console. - Once you've installed the older version via the link generated from the console, tap the link for the newer version from the console, **BUT DO NOT INSTALL THE UPDATE**. You should see that an update is availabe. - Open the already-installed older verson and you should see your implemented update type working : ) Following these laid-out items should help you properly test the feature. It might take a while for feature to actually work in production, so be patient. ## Conclusion Hopefully, you have been able to learn something about this feature. Other features can be implemented like deciding which kind of features should be immediately updates and which could be flexble and much more. Please feel free to email me at nerosilva522@gmail.com if you have any questions. Well then, till our next rodeo!

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully