0

We can scroll the text up and down but no scroll bar is shown.

My purpose in showing the scroll bar was to make the user aware that there is more text below.

showDialog(
  context: context,
  builder: (BuildContext context) {
    return AlertDialog(
      title: Text('Scrollable Alert Dialog'),
      content: SingleChildScrollView(
        child: Scrollbar(
          child: Column(
            children: [
              // add your scrollable content here
              // for example:
              for (var i = 1; i <= 20; i++)
                Text('Item $i'),
            ],
          ),
        ),
      ),
      actions: [
        TextButton(
          child: Text('Close'),
          onPressed: () => Navigator.of(context).pop(),
        ),
      ],
    );
  },
);

Snapshot of the resulting AlertDialog

2 Answers2

0

Perhaps the 20 items isn't enough to make it scrollable based on your viewport. SingleChildScrollView will be scrollable only when its child size is greater than its view port. Also, you may wrap the scrollable widget with Scrollbar .

content: Scrollbar( // preferable 
  child: SingleChildScrollView(
    child: Column(
      children: [
        // add your scrollable content here
        // for example:
        for (var i = 1; i <= 220; i++) Text('Item $i'), //here 
      ],
    ),
  ),
),
Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
0

This version worked! Thanks to Yeasin Sheikh.

Widget build(BuildContext context) {
  return AlertDialog(
  title: Text('Scrollable Alert Dialog'),
  content: Scrollbar(
  child: SingleChildScrollView(
    child: Column(
        children: [
          // add your scrollable content here
          // for example:
          for (var i = 1; i <= 20; i++)
            Text('Item $i'),
        ],
      ),
    ),
  ),
  actions: [
    TextButton(
      child: Text('Close'),
      onPressed: () => Navigator.of(context).pop(),
    ),
  ],
  );
}