在颤动中,我们要在小部件上方覆盖一个对话框。
按下按钮后,我们可以显示对话框。
但是,我们希望在显示喜欢加载对话框的小部件时显示该对话框。
我们实现了如下。
import 'package:flutter/material.dart';
class XxxxxWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
// [NG]We want to show dialog on Container widget.
// showMyDialog(context);
return Container(
child: FlatButton(
child: Text('Show'),
onPressed: () {
// [OK]We can show dialog.
showMyDialog(context);
},
),
);
}
void showMyDialog(BuildContext context) {
showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: const Text(
'Message',
),
actions: <Widget>[
FlatButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop(true);
},
),
],
);
},
); …Run Code Online (Sandbox Code Playgroud) 列的子级 CustomPainter 的大小变为 (0, 0)。
1)当我们刚刚使用CustomPaint和CustomPainter时,我们期望的大小被传递给CustomPainter,它按预期渲染。
2)当我们使用CustomPaint和CustomPainter作为Stack的子级时,我们期望的大小没有传递给CustomPainter。
3)但是当我们将它用作SizedBox.expand的子项时,我们期望的大小被传递给CustomPainter并被渲染。
4)当我们使用CustomPaint和CustomPainter作为Column的子项时,我们期望的大小没有传递给CustomPainter。我们正在研究解决该问题的方法。
5) 但是,它的高度要么是 0.0,要么是无穷大。我们希望它能够扩展到合适的尺寸。
import 'package:flutter/material.dart';
class TestWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
// 1) OK Size(360.0, 640.0)
// return CustomPaint(
// painter: TestPainter(),
// );
// 2) NG Size(0.0, 0.0)
// return Stack(
// children: <Widget>[
// CustomPaint(
// painter: TestPainter(),
// ),
// ],
// );
// 3) OK Size(360.0, 640.0)
// return Stack(
// children: <Widget>[
// SizedBox.expand(
// child: CustomPaint(
// painter: TestPainter(),
// ), …Run Code Online (Sandbox Code Playgroud)