Flutter app update alert dialog box.

 

App Update Alert :

Every app has new updates coming up every period of time or sometimes due to technical issues / bugs which in turn return in app uploads.

So when you make a app upload you need to make sure your users update the app to the latest available so for which we can make use of a alert box showing the recent changes in app and provide them asking user to update their app.

For this scenario we generally make use of a api to do so but again its a difficult task i.e., every one cannot do so because it involves server side coding.

To handle this scenario we use firebase remote config such that we provide info regarding the app update and based on which we ask user to update their app.

 

Pubspec.yaml :

We have added the firebase core and remote config dependency’s so as to make use of remote config functionality for app update alert.

 

dependencies:
  flutter:
    sdk: flutter

  firebase_core: ^1.10.6
  firebase_remote_config: ^1.0.3

main.dart :

We need to initialize the firebase to get started with usage of its services the same we did in void main().

And later we have fetched the based in which we will show the update alert dialog for the users here we are just looking in a tutorial perspective so i have just showed a alert dialog.

***In real time we need to make use of version code to analyze whether the user has updated the app or not and show App Update Alert based on it.

 

Providing the full code for app update alert box.

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MaterialApp(
    debugShowCheckedModeBanner: false,
    title: "Remote Config",
    home: FutureBuilder<RemoteConfig>(
      future: setupRemoteConfig(),
      builder: (BuildContext context, AsyncSnapshot<RemoteConfig> snapshot) {
        return Home(remoteConfig: snapshot.requireData);
      },
    ),
  ));
}

class Home extends StatefulWidget {
  final RemoteConfig remoteConfig;

  const Home({Key? key, required this.remoteConfig}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    var update = widget.remoteConfig.getBool("Update");

    return Scaffold(
      appBar: AppBar(
        title: const Text("Remote Config"),
      ),
      body: update
          ? showAlertDialog(context, widget.remoteConfig)
          : const Center(
              child: Text("Dashboard")),
      floatingActionButton: FloatingActionButton(onPressed: () async {
        try{
          await widget.remoteConfig.setConfigSettings(RemoteConfigSettings(
            fetchTimeout: Duration(seconds: 10),
            minimumFetchInterval: Duration.zero
          ));
          await widget.remoteConfig.fetchAndActivate();
          setState(() {

          });
        }catch(e){
          print(e.toString());
        }
      },
      child: Icon(Icons.refresh),),
    );
  }
}

Future<RemoteConfig> setupRemoteConfig() async {
  final RemoteConfig remoteConfig = RemoteConfig.instance;

  await remoteConfig.fetch();
  await remoteConfig.activate();

  return remoteConfig;
}

AlertDialog showAlertDialog(BuildContext context, RemoteConfig remoteConfig) {
  Widget cancel = TextButton(onPressed: () {}, child: const Text("Cancel"));
  Widget update = TextButton(onPressed: () {}, child: const Text("Update"));

  return AlertDialog(
    title: Text(remoteConfig.getString("Title")),
    content: Text(remoteConfig.getString("Message")),
    actions: <Widget>[cancel, update],
  );
}

 

Output :

The screen below depicts the usage of app update alert dialog using firebase remote config.

app update alert

If you have any query’s in this part of the tutorial on app update alert implementation do let us know in the comment section below.

If you like this tutorial do like and share us for more interesting updates.

 

Show Buttons
Hide Buttons
Read previous post:
Flutter firebase remote config tutorial

  Firebase Remote Config : Firebase Remote Config is the easiest way to customize your mobile app once you release...

Close