Flutter how to set container background as transparent color
You can achieve this simply with this:
...
color: Colors.red.withOpacity(0),
...
you can specify how much opacity you want by using decimal value from 0 to 1, 0 being fully transparent while 1 being fully opaque .
You can also do as below
backgroundColor: Color.fromRGBO(r, g, b, 0)
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,
...