Skip to content

Instantly share code, notes, and snippets.

@emisjerry
Created September 29, 2019 07:04
Show Gist options
  • Save emisjerry/04afacd51c311d6ca344e60c31368845 to your computer and use it in GitHub Desktop.
Save emisjerry/04afacd51c311d6ca344e60c31368845 to your computer and use it in GitHub Desktop.
Flutter demo #6, AlertDialog
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
void pn(num n) => print(n);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget scaffold = Scaffold(
appBar: AppBar(title: Text("My App")),
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Press button to alert!",
style: TextStyle(
color: Colors.red,
fontSize: 30,
),
),
RaisedButton(
onPressed: () {
alert(context);
},
color: Colors.blue,
textColor: Colors.white,
child: Text("Alert!"),
),
],
),
),
),
);
return scaffold;
}
void alert(BuildContext context) {
AlertDialog dialog = AlertDialog(
backgroundColor: Colors.yellow,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15)),
),
content: Row(
children: <Widget>[
Icon(
Icons.warning,
color: Colors.red,
size: 30,
),
Padding(padding: EdgeInsets.only(right: 10)),
Text(
"This is a dialog.",
style: TextStyle(
color: Colors.red,
fontSize: 30,
),
),
],
),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.pop(context, true);
},
child: Text(
"CLOSE",
style: TextStyle(color: Colors.black),
),
),
],
);
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => dialog,
);
//print("in alert()");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment