When I open a dialog in flutter I want the background to become a light blue with opacity as shown in the image below:
I’ve set the surfaceTintColor
of my Dialog
widget to the color I want, but it is not being applied. Instead I see the default elevation of the dialog. here is my code:
class PickImageDialog extends StatelessWidget {
const PickImageDialog({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Dialog(
surfaceTintColor: Theme.of(context).colorScheme.surfaceTint,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16))),
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 16, 10, 22),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
IconButton(
onPressed: () {
context.router.pop();
},
icon: Icon(Icons.clear),
),
Expanded(
child: Text(
AppStrings.pickImage,
textAlign: TextAlign.center,
),
),
],
),
SizedBox(
height: 26,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
height: 60,
width: 60,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
border: Border.all(
width: 2, color: Theme.of(context).primaryColor),
color: Theme.of(context).colorScheme.surfaceTint),
child: SvgPicture.asset(
AppVectors.camera,
color: Theme.of(context).primaryColor,
height: 28,
),
), Container(
height: 60,
width: 60,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
border: Border.all(
width: 2, color: Theme.of(context).primaryColor),
color: Theme.of(context).colorScheme.surfaceTint),
child: SvgPicture.asset(
AppVectors.gallery,
color: Theme.of(context).primaryColor,
height: 28,
),
),
],
)
],
),
),
);
}
}
2
Answers
If you want to show a dialog you can use
barrierColor
property, like this:And if you want to blur the background you can wrap your
Dialog
withBackdropFilter
in your PickImageDialog class:Salaam, For having a blur background first of all edit your
PickImageDialog
to this:by the way i didn’t see any codes to show your dialog if you haven’t implemented it before here is the code you need:
happy coding after Polytechnic!