删除灰色背景以显示抖动警报对话框

时间:2019-06-12 15:08:50

标签: flutter flutter-layout flutter-cupertino

我的Flutter应用中有一个CupertinoAlertDialog和AlertDialog。每次弹出对话框时,其背后的所有内容都会变暗。我想删除背景。我该怎么办?

CupertinoDialogAction(
        child: Text('Delete',
                style: TextStyle(color: Colors.red),
              ),
              onPressed: () async {
                await CommentActivity.delete(postData[index]['id'])
                  .then((response) {
                  if (response) {
                    setState(() {
                      postData.removeAt(index);
                      createPageActivity();
                      renderPageActivity();
                    });
                    Navigator.of(context).pop();
                  }
                });
              }
            )
          ],
        )

4 个答案:

答案 0 :(得分:2)

在showDialog方法中具有barrierColor属性的简单解决方案,我将白色设置为不透明度值为零,并且栅栏阴影消失了

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);
    },
  );

答案 1 :(得分:1)

部分解决问题的替代方法是使用几乎透明的颜色作为屏障:

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

答案 2 :(得分:0)

我认为您正在谈论对话框背景中的黑色推子... 是Material / cupertino实现的一部分,在Material中具有固定值Colors.black54。

您将必须复制showDialog()代码,并对其进行修改。

演示:

// 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),
    );
  }

这是您要找的吗?

答案 3 :(得分:0)

只需使用de navigator启动对话框,而不使用showDialog()并使用PageRouteBuilder

 holder.spinnerCart.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        int count=0;

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

            if(count >= 1) {

            }count++;
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
相关问题