Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a transparent full screen dialog on top of activity - Flutter

Tags:

I am trying to create a transparent full screen dialog on top of activity. I have tried following this thread but solution doesn't work.

In short , what I need is:

  • full screen dialog.
  • transparent background except for the widget I use for the dialog

here's my code:

To open dialog

void onNextBtnClick(){     var route = new MaterialPageRoute(         builder: (BuildContext context) =>         new GenreDialogUI(),fullscreenDialog: true     );     Navigator.of(context).push(route); } 

For Dialog view

import 'package:flutter/widgets.dart';  class HolePuncherPainter extends CustomPainter {   static final clearPaint = new Paint()     ..color = Colors.transparent,     ..blendMode = BlendMode.clear;    const HolePuncherPainter();    @override   void paint(Canvas canvas, Size size) {     canvas.drawRect(         new Rect.fromLTWH(0.0, 0.0, size.width, size.height), clearPaint);   }    @override   bool shouldRepaint(CustomPainter oldDelegate) {     return true;   } }  class GenreDialogUI extends StatefulWidget {    @override    _GenreDialogUI createState() => new _GenreDialogUI(); }  class _GenreDialogUI extends State<GenreDialogUI>  {    @override   Widget build(BuildContext context) {     return new Scaffold(       appBar: addAppbar(),       body: new CustomPaint(         painter: HolePuncherPainter(),         child: new Container(         color: Colors.transparent,         alignment: Alignment.center,         child: UtilCommonWidget.addText('Transparent Dialog', Colors.red, 22.0, 1),         ),       ),     );   } } 
like image 218
Rafiqul Hasan Avatar asked Jul 10 '18 06:07

Rafiqul Hasan


People also ask

How do I make dialog box full screen on flutter?

Flutter Full Screen Dialog By Using showDialog method we cannot show full-screen Dialog. If we want to show dialog in full screen we must use showGeneralDialog method provided by Flutter SDK. There are some interesting parameter available in showGeneralDialog method. barrierColor – Change dropshadow outside the dialog.

How do you create a dialog box in flutter?

Creating a full-screen dialog cannot be done by the showDialog method. Instead, use the showGeneralDialog method. In the pageBuilder , you should specify your dialog widget implementation. As a first widget, you can specify the SizedBox.

How do you customize dialog in flutter?

Flutter custom Alert Dialog If you want to implement more advanced custom Dialog, you can use Dialog widget for that. Instead of the AlertDialog , in here we return Dialog widget. The showDialog method will remain the same. You can use a Container widget to set relevant height for the Dialog.


2 Answers

Navigator.of(context).push(PageRouteBuilder(     opaque: false,     pageBuilder: (BuildContext context, _, __) {         return YourFullScreenAlertDialog()     } )); 

YourFullScreenAlertDialog could be a widget that has a background color, Colors.transparent, like @creativecreatorormaybenot mentioned earlier.

like image 74
gareoke Avatar answered Oct 18 '22 17:10

gareoke


For me the following worked:

showDialog(   context: context,   builder: (_) => Material(     type: MaterialType.transparency,     child: Center(       // Aligns the container to center       child: Container(         // A simplified version of dialog.         width: 100.0,         height: 56.0,         color: Colors.green,         child: Text('jojo'),       ),     ),   ), ); 
like image 40
midi Avatar answered Oct 18 '22 16:10

midi