Alert Dialog in Flutter


Here is the simple program How to use Aler Dialog widget in Flutter.


Source Code

import 'package:flutter/material.dart';
import 'dart:async';

void main() {
  runApp(MaterialApp(
    home: MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Future showdialog(BuildContext context, String message) async {
    return showDialog(
        context: context,
        child: new AlertDialog(
          title: new Text(message),
          actions: <Widget>[
            new FlatButton(
                onPressed: () => Navigator.pop(context), child: new Text("OK"))
          ],
        ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Alert Dialog"),
        ),
        body: Center(
          child: RaisedButton(
            child: Text(
              "Click Me",
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () {
              showdialog(context, "Welcome To Tutor Joes");
            },
            color: Colors.blue,
          ),
        ));
  }
}
To download raw file Click Here

Learn All in Tamil © Designed & Developed By Tutor Joes