Building a Flutter AlertDialog in just 15 minutes

Search for a command to run...

No comments yet. Be the first to comment.
This series focuses on introducing you to short and crisp code snippets to build beautiful UI & concise UX with Flutter. These are specifically aligned to help newbie Flutter Devs.
In this post, we’ll have an overview of Flutter, the latest buzz in the App Development market. Flutter is gaining popularity faster than any other framework. Some say it is Google’s answer to Facebook’s React Native, but that debate is for later. Le...
The offer came via on-campus hiring at Thapar Institute, Patiala. Navi came to our campus in September 2021 to hire Fresh Graduates for SDE-1 roles. Company 💪🏻 At Navi, our mission is to build financial services that are simple, accessible, and af...

Agenda? A lot of people ask me, how to get started with tech. If you have been asking this to someone, this might be the answer. Let me try to answer it by taking some relevant programming fields in context. Options? According to me, there are four m...

It was a cold winter night of November when I was scrolling through my LinkedIn and a mail popped up on my cell phone. The subject said, "2021 Application Engineering Internship Opportunity with Google India!". At first, I was like, "Ahh.. this seems...

❔ Intro to JPMC’s Code for Good According to JPMorgan Chase & Co., Code for Good is a series of hackathons hosted in JPMorgan’s global technology centers. During this event, participants spend 12–24 hours with our employees, developing creative solu...

Shivam's Blog
9 posts
Hey! I'm Shivam. I'm an award-winning Software Engineer & a CS major with a background in Full Stack Mobile Engineering.
More about me? https://goyalshivam.com/ it is.
The AlertDialog is basically a Popup in Flutter. Whenever you want to create a floating box that is centered on the page, you can simply use an AlertDialog. The implementation of the same is very easy and has been provided in-built with Flutter SDK. So, let's dive in… 👻
In this tutorial, you’ll build a mobile app featuring an AlertDialog / Popup in Flutter. The AlertDialog will have the following features:
Animated loader GIF
Customized actions buttons
Curved Edges

This tutorial focuses on adding an AlertDialog to the Flutter app. Non-relevant concepts and code blocks are glossed over and are provided for you to simply copy and paste.
The detailed steps to install Flutter on your personal computer & getting started with Flutter is available in the following blog post
const AlertDialog({
Key key,
Widget title,
EdgeInsetsGeometry titlePadding,
TextStyle titleTextStyle,
Widget content,
EdgeInsetsGeometry contentPadding: const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
TextStyle contentTextStyle,
List<Widget> actions,
Color backgroundColor,
double elevation,
String semanticLabel,
ShapeBorder shape
})
Download the GIF by right-clicking, and saving it as listening.gif at /{%PROJECTROOT%}/assets/images/listening.gif

Credits: Bendt on Pinterest
Import the GIF to your project by adding the file path to your pubspec.yaml file.
...
flutter:
uses-material-design: true
assets:
- assets/images/listening.gif
...
Create a file named voicePayDialog.dart in the same directory as of your main.dart file and amend the file with the following code:
import 'package:flutter/material.dart';
class VoicePay extends StatefulWidget {
@override
_VoicePayState createState() => _VoicePayState();
}
class _VoicePayState extends State<VoicePay> {
@override
Widget build(BuildContext context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(25),
),
),
title: Text(
'VoicePay',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.w700, fontSize: 25.0),
),
content: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/listening.gif'),
SizedBox(height: 10.0),
Container(
alignment: Alignment.center,
height: 45.0,
child: Text(
'Tap on mic to VoicePay',
style: TextStyle(fontSize: 20.0),
textAlign: TextAlign.center,
),
),
SizedBox(height: 30.0),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(Icons.keyboard),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.mic),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.translate),
onPressed: () {},
),
],
),
],
),
);
}
}
To show the AlertDialog / Popup add the following code to onPressed or onTap parameter of any button in your main.dart file:
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return VoicePay();
},
);
},
Remember to import
voicePayDialog.dartinmain.dart
Connect your Emulator or physical Android device to test the application.
Click on Build & Run.
And Boooom 🧨, your app is ready to launch.
You have completed this tutorial and have built a Flutter app with an AlertDialog! Also, in the meantime, you integrated GIFs in the App.