一、問題場景
嘗試自定義一個 Dialog,但是不顯示設置的佈局,主要代碼如下:
class MyDialog extends Dialog {
@override
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
child: Container(
width: 100,
height: 100,
color: Colors.blue,
),
);
}
}
二、問題解決
class MyDialog extends Dialog {
@override
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
child: Center(
child: Container(
width: 100,
height: 100,
color: Colors.blue,
),
),
);
}
}
說明:將佈局用 Center 包裹起來後就不存在顯示問題了。