I found this question but doesn't work for me.
I also play with Opacity
widget and decoration color of Container
. But didn't find solution It always display white background color when I set it transparent.
Look at below image, Instead of red color it should be transparent.
Below are my code:
_showAlertDialog(String strTitle, String strDetails) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
contentPadding: EdgeInsets.zero,
content: Stack(
children: <Widget>[
Opacity(
opacity: 1, // Also tried to set 0
child: Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Color.fromRGBO(255, 0, 0, 0.5) // I played with different colors code for get transparency of color but Alway display White.
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 50,
padding: EdgeInsets.only(left: 10, right: 10, top: 2),
color: Theme.of(context).primaryColor,
child: Center(
child: Text(
strTitle,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
fontSize: 14),
maxLines: 2,
),
),
),
Flexible(
child: Container(
color: Colors.white,
padding: EdgeInsets.all(10),
child: SingleChildScrollView(
child: Text(
strDetails,
style: TextStyle(color: Colors.black87, fontSize: 12, fontWeight: FontWeight.w400),
),
),
),
),
],
),
),
),
Positioned(
top: 0,
right: 0,
child:
Container(
height: 24,
width: 24,
child: DecoratedBox(
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.close, color: Theme.of(context).primaryColor, size: 18,), onPressed: () {
Navigator.of(context).pop();
}),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12)
),
),
)
)
],
),
);
});
}
}
To set background color for Container widget, set its color property with the required Color value or set the decoration property with required background color value in it.
static const Color transparent = Color(0x00000000); Flutter. material. Colors.
You can actually apply a hex code color that is transparent. The hex code for transparent white (not that the color matters when it is fully transparent) is two zeros followed by white's hex code of FFFFFF or 00FFFFFF.
Steps to set the background image: Step 1: Add the Container widget. Step 2: Add the decoration parameter (inside Container) and assign the BoxDecoration class. Step 3: Add the image parameter (inside BoxDecoration) and assign the DecorationImage class.
The AlertDialog
Widget has a backgroundColor
property , just set it to transparent.
AlertDialog(
contentPadding: EdgeInsets.zero,
backgroundColor: Colors.transparent,
And remove the BoxDecoration
Update
Looks like backgroundColor
is not available on Flutter 1.0.0 yet.
(I'm on dev channel)
stable: https://github.com/flutter/flutter/blob/stable/packages/flutter/lib/src/material/dialog.dart
dev: https://github.com/flutter/flutter/blob/dev/packages/flutter/lib/src/material/dialog.dart
Checking the source code of Dialog , I found it was using the dialogBackgroundColor
from theme. Try this easy way:
showDialog(
context: context,
builder: (BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(dialogBackgroundColor: Colors.transparent),
child: AlertDialog(
contentPadding: EdgeInsets.zero,
content: Stack(
children: <Widget>[
Container(
margin: EdgeInsets.all(8.0),
color: Colors.white,
...
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