I have a problem to implement the third code here https://www.codegrepper.com/search.php?answer_removed=1&q=alert%20dialog%20aler%20dialog%20flutter
class _HomepageState extends State<Homepage> {
@override
void initState() {
super.initState();
setState(() {
showAlertDialog();
});
}
@override
Widget build(BuildContext context) {
return ListView(
padding: EdgeInsets.all(20),
children: <Widget>[
Center(
child: Text(
'Welcome',
style: TextStyle(fontSize: 30),
textAlign: TextAlign.center,
),
),
SizedBox(height: 30),
Text(
"News",
style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
),
SizedBox(height: 20),
],
);
}
showAlertDialog(BuildContext context) {
// set up the button
Widget okButton = FlatButton(
child: Text("OK"),
onPressed: () {},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Text("My title"),
content: Text("This is my message."),
actions: [
okButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
}
the call off "showAlertDialog();" is still error because it require parameter typed "BuildContext"
If there are another ways to do it, please tell me, thank you very much