I'm new to flutter and need to create a gallery app that needs a custom dialog box to show the selected image. How can I implement that?
Adding simple Dialog to your screen in pretty easy in Flutter. Before adding Dialog you must call showDialog function to change current screen state to show the intermediate Dialog popup. In here we use AlertDialog widget to show simple Dialog with title and some text in the body.
We need the function "showDialog()" to display the Material Dialog on the Page. In Flutter everything is a Widget. So the Dialog is also a Material Design Widget.
You can Use Align widget and align your dialog widget as per your need. Here in example i am setting it to the bottomCenter that is Alignment(0, 1) . Example code: Align( alignment: Alignment(0, 1), child: Material( shape: RoundedRectangleBorder(borderRadius: BorderRadius.
Edit the the widget itself: Under the AlertDialog there is a ButtonBar widget where you can use alignment: MainAxisAlignment. spaceBetween to align the buttons correctly. See this answer for an example of a custom AlertDialog widget. Show activity on this post.
Use Dialog class which is a parent class to AlertDialog class in Flutter. Dialog widget has a argument , "shape" which you can use to shape the Edges of the Dialog box.
Here is a code sample:
Dialog errorDialog = Dialog( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)), //this right here child: Container( height: 300.0, width: 300.0, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Padding( padding: EdgeInsets.all(15.0), child: Text('Cool', style: TextStyle(color: Colors.red),), ), Padding( padding: EdgeInsets.all(15.0), child: Text('Awesome', style: TextStyle(color: Colors.red),), ), Padding(padding: EdgeInsets.only(top: 50.0)), TextButton(onPressed: () { Navigator.of(context).pop(); }, child: Text('Got It!', style: TextStyle(color: Colors.purple, fontSize: 18.0),)) ], ), ), ); showDialog(context: context, builder: (BuildContext context) => errorDialog);}
Just call this method:
void showCustomDialog(BuildContext context) { showGeneralDialog( context: context, barrierLabel: "Barrier", barrierDismissible: true, barrierColor: Colors.black.withOpacity(0.5), transitionDuration: Duration(milliseconds: 700), pageBuilder: (_, __, ___) { return Center( child: Container( height: 240, child: SizedBox.expand(child: FlutterLogo()), margin: EdgeInsets.symmetric(horizontal: 20), decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(40)), ), ); }, transitionBuilder: (_, anim, __, child) { Tween<Offset> tween; if (anim.status == AnimationStatus.reverse) { tween = Tween(begin: Offset(-1, 0), end: Offset.zero); } else { tween = Tween(begin: Offset(1, 0), end: Offset.zero); } return SlideTransition( position: tween.animate(anim), child: FadeTransition( opacity: anim, child: child, ), ); }, ); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With