可滚动的 Alertdialog Flutter
Scrollable Alertdialog Flutter
我正在努力使 Flutter 中的警报对话框可滚动。我尝试了几种方法,到目前为止,这是效果最好的一种:
Widget _buildPopupDialog(BuildContext context) {
List<IconData> _iconsTable = [
Icons.build,
Icons.format_paint,
Icons.assignment,
Icons.group_work,
Icons.home,
Icons.feedback,
...
];
return new AlertDialog(
title: const Text('Popup example'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Column(
children: new List.generate(26, (int index) {
return new Positioned(
child: new TableButtons(
iconData: _iconsTable[index]),
);
}),
),
],
),
),
],
),
目前,图标正在显示,但没有滚动。我收到的错误消息是:“A RenderFlex 在底部溢出 170 像素。”我想我必须使用 ListView 但我不确定在哪里添加它,因为它会导致错误。如有任何帮助,我们将不胜感激!
您有许多仅包含 1 个 child 的列,因此您必须稍微清理一下代码:
Widget _buildPopupDialog(BuildContext context) {
List<IconData> _iconsTable = [
Icons.build,
Icons.format_paint,
Icons.assignment,
Icons.group_work,
Icons.home,
Icons.feedback,
...
];
return new AlertDialog(
title: const Text('Popup example'),
content: SingleChildScrollView(
child: new Column(
children: new List.generate(26, (int index) {
return new Positioned(
child: new TableButtons(
iconData: _iconsTable[index]),
);
}),
),
),
我认为您使用了不需要的 Column()
小部件。
试试这个。
return AlertDialog(
title: const Text('Popup example'),
content: SingleChildScrollView(
child: new Column(
children: new List.generate(50, (int index) {
return new Positioned(
child: Icon(
Icons.camera
),
);
}),
),
),
);
我正在努力使 Flutter 中的警报对话框可滚动。我尝试了几种方法,到目前为止,这是效果最好的一种:
Widget _buildPopupDialog(BuildContext context) {
List<IconData> _iconsTable = [
Icons.build,
Icons.format_paint,
Icons.assignment,
Icons.group_work,
Icons.home,
Icons.feedback,
...
];
return new AlertDialog(
title: const Text('Popup example'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Column(
children: new List.generate(26, (int index) {
return new Positioned(
child: new TableButtons(
iconData: _iconsTable[index]),
);
}),
),
],
),
),
],
),
目前,图标正在显示,但没有滚动。我收到的错误消息是:“A RenderFlex 在底部溢出 170 像素。”我想我必须使用 ListView 但我不确定在哪里添加它,因为它会导致错误。如有任何帮助,我们将不胜感激!
您有许多仅包含 1 个 child 的列,因此您必须稍微清理一下代码:
Widget _buildPopupDialog(BuildContext context) {
List<IconData> _iconsTable = [
Icons.build,
Icons.format_paint,
Icons.assignment,
Icons.group_work,
Icons.home,
Icons.feedback,
...
];
return new AlertDialog(
title: const Text('Popup example'),
content: SingleChildScrollView(
child: new Column(
children: new List.generate(26, (int index) {
return new Positioned(
child: new TableButtons(
iconData: _iconsTable[index]),
);
}),
),
),
我认为您使用了不需要的 Column()
小部件。
试试这个。
return AlertDialog(
title: const Text('Popup example'),
content: SingleChildScrollView(
child: new Column(
children: new List.generate(50, (int index) {
return new Positioned(
child: Icon(
Icons.camera
),
);
}),
),
),
);