Flutter: Force Upgrade your app users(How to)
4 min readJan 29, 2023
Flutter How To: Simple | To the Point| Short
Flutter Dev Level: Intermediate
1.0 Objective
- To be able to Force all or selected version users to upgrade to the latest version of your app on iOS and Android.
2.0 Sample Project Github Link
Step- 1 Create an app upgrade account
- Go https://appupgrade.dev/ and create a new account
Step -2 Create new Project on App upgrade
Step-3 Copy the API key
- Once the project is created, you’ll be redirected to projects page. Alternatively, you can click on projects on the top of the menu.
- Now click on API key of the project card you just created
- Copy the API key
- Minimise the window and go to your Flutter project.
Step -4 Install the Flutter App Upgrade SDK
- In the terminal, go to the root folder of your project and paste
flutter pub add app_upgrade_flutter_sdk
- Alternatively, you can paste this from pubspec.yaml (Make sure you pick the latest version from pub.dev)
app_upgrade_flutter_sdk: ^1.0.4
Step-5 In your main.dart file, import
import 'package:app_upgrade_flutter_sdk/app_upgrade_flutter_sdk.dart';
Step -6 Create App Info object within main file (Sample Final file in Step 9)
AppInfo appInfo = AppInfo(
appName: 'flutter_force_update', // Your app name
appVersion: '1.0.2', // Your app version
platform: Platform.operatingSystem, // App Platform, android or ios
environment:
'development', // Environment in which app is running, production, staging or development etc.
appLanguage: 'en' // App language ex: en, es etc. Optional.
);
Important: appVersion is the current version of the app.
- We will use this object in Step 8.
Step -7 Create Dialog config object (Optional)
DialogConfig dialogConfig = DialogConfig(
dialogStyle: DialogStyle.material,
title: 'App update required!',
updateButtonTitle: 'Update Now',
laterButtonTitle: 'Later');
- We will use this object in Step 8
Step -8: Wrap you root body widget inside AppUpgradeAlert
AppUpgradeAlert(
xApiKey: 'NWY3MjkzZjgtOWRiMi00Y2ZjLThjN2EtNjkzZjk3MTc5ZjE5',
appInfo: appInfo,
dialogConfig: dialogConfig,
child: const Center(child: Text('Flutter Demo Home Page'))),
),
Important: The xAPI key is the same key we copied in Step 3.
Step -9: Complete file just in case you want to get better understanding of past 3 steps
import 'dart:io';
import 'package:app_upgrade_flutter_sdk/app_upgrade_flutter_sdk.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
AppInfo appInfo = AppInfo(
appName: 'flutter_force_update', // Your app name
appVersion: '1.0.2', // Your app version
platform: Platform.operatingSystem, // App Platform, android or ios
environment:
'development', // Environment in which app is running, production, staging or development etc.
appLanguage: 'en' // App language ex: en, es etc. Optional.
);
DialogConfig dialogConfig = DialogConfig(
dialogStyle: DialogStyle.material,
title: 'App update required!',
updateButtonTitle: 'Update Now',
laterButtonTitle: 'Later');
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: AppUpgradeAlert(
xApiKey: 'NWY3MjkzZjgtOWRiMi00Y2ZjLThjN2EtNjkzZjk3MTc5ZjE5',
appInfo: appInfo,
dialogConfig: dialogConfig,
child: const Center(child: Text('Flutter Demo Home Page'))),
),
);
}
}
Step -10 In your browser, go to https://appupgrade.dev/dashboard
- On your dashboard click version button on your project you created earlier.
Step -11 Create Version that needs to be upgraded to Latest
- Click on new version on top right corner
- Fill the details
* VERY VERY IMPORTANT — App version is the older version from which you want users to upgrade to latest. NOT THE LATEST VERSION. Don’t get confused.
- Make sure force upgrade is ticked.
- You have to create two seperate ones for android and iOS and for all the versions that need to upgrade.
Step -12 Test
iOS
Android
That’s all for this one. Hope it helped :-)
Github link:
https://github.com/AbdurM/flutter-force-upgrade
Please find more flutter articles here: https://medium.com/@rafayk66/abdurs-flutter-articles-c201eff334b8
You can find me on
LinkedIn — https://www.linkedin.com/in/knowabdur
Twitter: — https://twitter.com/AbdurDeveloper
#flutter #flutterdeveloper #AbdurDeveloper #fluttercommunity