Updated 27 April 2023
In this article, we will learn about in-app update in flutter for our apps .
When an app update is available on the Google Play Store, active users are prompted to upgrade the app using the in-app updates functionality of the Google Play Core libraries.
Android 5.0 (API level 21) or higher-powered devices can use the in-app updates capability. Additionally, only Chrome OS, Android tablets, and Android mobile devices can receive in-app upgrades. Currently, iOS doesn’t have this feature. On an iOS device, calling the aforementioned methods will result in a non-implemented exception.
Check out more about our Flutter app development services.
Users of the app can test out new features, as well as take advantage of speed enhancements and bug fixes, when they keep the software updated on their devices.
While some users choose to enable background updates when using an unmetered connection, other users may prefer to be notified to install updates, which is why in-app updates were created.
You may quickly ask the user to upgrade the app using in-app updates.
Update dialogues come in two flavours: Required and update. You can choose to keep one or both, depending on your preferences. For required update, If user clicks on Update button, we will redirect the user to the PlayStore or AppStore page of our device and for optional if we click on later option it closes the popup dialog for now and it pops-up again when app is opened again.
Flexible updates offer seamless state monitoring and background download and installation. When it’s allowed for the user to use the app while the update is downloading, this UX flow is appropriate. For instance, you might want to entice customers to explore a novel feature that is not essential to your app’s essential functioning.
Immediate updates are fullscreen UX routines that prevent users from continuing to use an app without updating and restarting it. When an update is essential to your app’s core operation, this UX flow works well. Google Play manages the installation of the update and restart of the app once a user agrees to an immediate update.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
import 'dart:async'; import 'package:flutter/material.dart'; import 'package:in_app_update/in_app_update.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { AppUpdateInfo? _updateInfo; GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey(); bool _flexibleUpdateAvailable = false; // Platform messages are asynchronous, so we initialize in an async method. Future<void> checkForUpdate() async { InAppUpdate.checkForUpdate().then((info) { setState(() { _updateInfo = info; }); }).catchError((e) { showSnack(e.toString()); }); } void showSnack(String text) { if (_scaffoldKey.currentContext != null) { ScaffoldMessenger.of(_scaffoldKey.currentContext!) .showSnackBar(SnackBar(content: Text(text))); } } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( key: _scaffoldKey, appBar: AppBar( title: const Text('In App Update Example App'), ), body: Padding( padding: const EdgeInsets.all(8.0), child: Column( children: <Widget>[ Center( child: Text('Update info: $_updateInfo'), ), ElevatedButton( child: Text('Check for Update'), onPressed: () => checkForUpdate(), ), ElevatedButton( child: Text('Perform immediate update'), onPressed: _updateInfo?.updateAvailability == UpdateAvailability.updateAvailable ? () { InAppUpdate.performImmediateUpdate() .catchError((e) => showSnack(e.toString())); } : null, ), ElevatedButton( child: Text('Start flexible update'), onPressed: _updateInfo?.updateAvailability == UpdateAvailability.updateAvailable ? () { InAppUpdate.startFlexibleUpdate().then((_) { setState(() { _flexibleUpdateAvailable = true; }); }).catchError((e) { showSnack(e.toString()); }); } : null, ), ElevatedButton( child: Text('Complete flexible update'), onPressed: !_flexibleUpdateAvailable ? null : () { InAppUpdate.completeFlexibleUpdate().then((_) { showSnack("Success!"); }).catchError((e) { showSnack(e.toString()); }); }, ) ], ), ), ), ); } } |
In this blog, we learned how to implement in-app update in flutter using in_app_update.
Thank you for reading the blog. Please visit our mobikul blog site for more of these insightful articles about the newest technological trends.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.