Ask Your Question
3

How can you apply a gradient to the barrier color of a flutter showDialog or AlertDialog?

asked 2022-02-22 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-08-09 02:00:00 +0000

ladyg gravatar image

To apply a gradient to the barrier color of a flutter showDialog or AlertDialog, you can define a BoxDecoration with a LinearGradient as the background of the AlertDialog. Here's an example:

  1. First, define the gradient in a variable:
final gradient = LinearGradient(
  begin: Alignment.topRight,
  end: Alignment.bottomLeft,
  colors: [
    Colors.blue,
    Colors.red,
  ],
);
  1. Then, wrap your showDialog or AlertDialog widget with a Container with the BoxDecoration applied:
showDialog(
  context: context,
  builder: (context) => Container(
    decoration: BoxDecoration(
      gradient: gradient,
    ),
    child: AlertDialog(
      title: Text('Title'),
      content: Text('Content'),
    ),
  ),
);

This will apply the gradient as the background of the AlertDialog and show it with the gradiented barrier color.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-22 11:00:00 +0000

Seen: 8 times

Last updated: Aug 09 '21