Scrollable Alertdialog Flutter

Issue

I am struggling to make the alert dialogue box scrollable in Flutter. I have tried a few methods and so far this is the one that is working best:

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

Currently, the icons are showing up but it is not scrolling. The error message I am receiving is: "A RenderFlex overflowed by 170 pixels on the bottom." I think I have to use ListView but I am not sure where to add it as it is causing errors. Any help would be appreciated!

Solution

You have to many Column containing only 1 child, so you must clean up a bit your code :

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

Answered By – BabC

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *