showGeneralDialog无法正常工作

时间:2018-11-04 11:47:45

标签: dart flutter

代码:

void showNow() {
    showGeneralDialog(
      context: context,
      pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
        return Container(
          width: 200.0,
          height: 200.0,
          color: Colors.orange,
        ); 
      },
      barrierDismissible: true,
      barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
      barrierColor: Colors.black,
      transitionDuration: const Duration(milliseconds: 200),
    );
}

但是此对话框占用了整个空间,而不是我使用的200.0 widthheight。我尝试将Container包装在Scaffold中,但是随后barrierDismissiblebarrierColor似乎不起作用。我也改变了他们的价值观,但没有运气。

1 个答案:

答案 0 :(得分:0)

在包装小部件中包装容器:

void showNow() {
    showGeneralDialog(
      context: context,
      pageBuilder: (BuildContext buildContext, Animation<double> animation,
          Animation<double> secondaryAnimation) {
        return Wrap(
          children: <Widget>[
            Container(
              width: 200.0,
              height: 200.0,
              color: Colors.orange,
            ),
          ],
        );
      },
      barrierDismissible: true,
      barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
      barrierColor: Colors.black,
      transitionDuration: const Duration(milliseconds: 200),
    );
  }