4

I am creating a StatefulWidget which have a transparent background. Code for same is:

return Scaffold(
  body: Builder(
    builder: (context) => Material(
          color: Colors.black.withOpacity(0.75),
          child: new SafeArea(
            child: Center(
              child: Container(
                color: Colors.white,
                child: ListView(
                  children: <Widget>[
                    resetPasswordLabel,
                    inputFields,
                    doneButton(context),
                  ],
                ),
                height: 250.0,
                margin: EdgeInsets.only(left: 20.0, right: 20.0),
              ),
            ),
          ),
        ),
  ),
);

Problem: When I am opening this widget using Navigator the transparent color is visible for 1 - 2 seconds and after it turns to the black background.

Output: enter image description here

Accepted Output should be: enter image description here

Please assist me here.

Rahul Sharma
  • 12,515
  • 6
  • 21
  • 30

2 Answers2

2

You can create a custom dialog and open it with below line...

Navigator.of(context).push(
    PageRouteBuilder(
        pageBuilder: (context, _, __) => CustomAlertDialog(), opaque: false),
);

The opaque: false will keep background transparent.

Sanket Vekariya
  • 2,848
  • 3
  • 12
  • 34
1

When you open a new "page" with push state, the old "page" or state is disposed until you call Navigator.pop(context). If you want to have a effect shown in the screenshot you provided, use a dialog.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
dshukertjr
  • 15,244
  • 11
  • 57
  • 94