Juthi Sarker Aka
Juthi Sarker Aka

Reputation: 2465

Can't increase the width of an dialog box in flutter

I need to build a pop up dialog box in my app. I am using Dialog class and wrapped it with SizedBox class to increase the width of the dialog box. But, the width of the dialog box is not increasing. How can I increase the width of it?

onTap: () {
showDialog(
    context: context,
    child:SizedBox(
        width: 900,
        child: Dialog(
            backgroundColor :Colors.white,
            insetAnimationDuration: const Duration(milliseconds: 10),
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
            child: Container(
                child: Column(
                    children: <Widget>[
                        Text('hello'),
                        FlatButton(
                        onPressed: () {
                            Navigator.of(context).pop();
                        },
                        child: new Text("OK"),
                        ),
                    ]
                ),
            ),  
        ),
    ),
);
},

Upvotes: 7

Views: 13282

Answers (1)

Chetan Pawar
Chetan Pawar

Reputation: 404

Try this

showDialog(
  context: context,
  builder: (context) {
    return Dialog(
      backgroundColor: Colors.white,
      insetAnimationDuration: const Duration(milliseconds: 100),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
      child: Container( // use container to change width and height
        height: 200,
        width: 400,
        child: Column(
          children: <Widget>[
            Text('hello'),
            FlatButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: new Text("OK"),
            ),
          ],
        ),
      ),
    );
  },
);

I replaced child parameter of with builder, since child is deprecated.

It is margined from screen boundaries, so it can't cover the whole screen, but can cover up to a limit.

Upvotes: 8

Related Questions