Remove grey background for flutter alert dialog

An alternative solution that partially solves the problem is using an almost transparent color for the barrier:

showDialog<void>(
      barrierColor: Color(0x01000000),
)

I think you're talking about the black fader in the background of the dialog... Is part of the material/cupertino implementations, in Material has a fixed value of Colors.black54.

You will have to copy the showDialog() code, and modify it.

Demo:

// common Dialog widget shown in both implementation. 
  Widget buildDialog(BuildContext context) {
    return CupertinoDialogAction(
      child: Text(
        'Delete',
        style: TextStyle(color: Colors.red),
      ),
      onPressed: () async {
        Navigator.of(context).pop();
      },
    );
  }

  void openDialog(BuildContext context) {
    // open custom dialog.
    openCustomDialog(context);

    // open default dialog.
//    openFlutterDialog(context);

  }

  // regular Fluter showDialog()
  void openFlutterDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (ctx) {
        return buildDialog(ctx);
      },
    );
  }

  void openCustomDialog(BuildContext context) {
    showCustomDialog(
      context: context,
      builder: (ctx) {
        return buildDialog(ctx);
      },
    );
  }

  // custom implementation of showDialog()...
  Future<T> showCustomDialog<T>({
    @required BuildContext context,
    bool barrierDismissible = true,
    WidgetBuilder builder,
  }) {
    assert(debugCheckHasMaterialLocalizations(context));
    final ThemeData theme = Theme.of(context, shadowThemeOnly: true);
    return showGeneralDialog(
      context: context,
      pageBuilder: (BuildContext buildContext, Animation<double> animation,
          Animation<double> secondaryAnimation) {
        final Widget pageChild = Builder(builder: builder);
        return SafeArea(
          child: Builder(builder: (BuildContext context) {
            return theme != null
                ? Theme(data: theme, child: pageChild)
                : pageChild;
          }),
        );
      },
      barrierDismissible: barrierDismissible,
      barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
      // KEY PART TO MODIFY, Flutter doesn't allow a transparent Color,
      // values under opacity .01 are considered transparent and will throw an error.
      // But this value is transparent enough.
      barrierColor: Colors.black.withOpacity(0.01),

            // you can modify the default FadeTransition duration here.
      transitionDuration: const Duration(milliseconds: 2000),
    );
  }

Is this what you were looking for?


Simple solution with barrierColor property in showDialog method which I set white color with opacity value zero and barrier shadow is vanished

AlertDialog alert = AlertDialog(
    backgroundColor: Colors.transparent,
    elevation: 0,
    content: new Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Loader(),
      ],
    ),
  );
  showDialog(
    barrierColor: Colors.white.withOpacity(0),
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return WillPopScope(
            onWillPop: (){},
          child: alert);
    },
  );

Just launch the dialog with de navigator instead of using the showDialog() and use a PageRouteBuilder

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