Is it possible to make a common class to show pop up (alert dialogues) in flutter. If so please help me with an example.
Asked
Active
Viewed 676 times
1
-
https://stackoverflow.com/questions/53844052/how-to-make-an-alertdialog-in-flutter – DAMMAK Jan 15 '20 at 07:41
-
does the link actually help, is that what you want? – DAMMAK Jan 15 '20 at 08:06
-
But this does'nt say anything about a common class for alert dialogues – fizik bata Jan 15 '20 at 08:54
2 Answers
1
create popups.dart
inside your popups.dart
void showYourPopUp(context){
showDialog(
context: context,
builder: (_)=> AlertDialog(
backgroundColor: Colors.transparent,
content: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 4.0,sigmaY:4.0) //this is for background blur only you can remove BackdropFilter if you want
child: *your popup design*
)
)
);
}
then import popups.dart in the class you want to use it e.g
this is your main.dart
import "your_app/popups.dart"
how to use:
GestureDetector(
onTap(){
showYourPopUp(context);
}
)

Qonvex620
- 3,819
- 1
- 8
- 15
0
Here is the dialog class you can use- DeleteHomeDialog will be the common class
onTap: (){
showDeleteDialog();
}
showDeleteDialog() {
showDialog(
context: context,
builder: (BuildContext context) =>
DeleteHomeDialog(),
);
}
and,
class DeleteHomeDialog extends StatelessWidget {
DeleteHomeDialog();
@override
Widget build(BuildContext context) {
dialogContent(BuildContext context) {
return Stack(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(10, 15, 10, 10),
margin: EdgeInsets.only(top: 10),
decoration: new BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 10.0,
offset: const Offset(0.0, 10.0),
),
],
),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("Alert", style: TextStyle(color: Colors.red, fontSize: 18, fontWeight: FontWeight.bold),),
Container(margin: EdgeInsets.fromLTRB(10, 15, 10, 0),
child: Text("Are you sure you want to delete ?", style: TextStyle(color: Colors.red, fontSize: 18),),
),
Container(
margin: EdgeInsets.all(20),
child: RaisedButton(
child: Text("Cancel"),
onPressed: () {
Navigator.pop(context);
},
color: Colors.red,
textColor: Colors.white,
padding: EdgeInsets.fromLTRB(20, 12, 20, 12),
splashColor:Colors.red,
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
),
)
],
),
)
],
);
}
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
elevation: 0.0,
backgroundColor: Colors.transparent,
child: dialogContent(context),
);
}
}

Ankit Kumar Saini
- 33
- 5