skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

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

  2. 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 
          ],
        ),
      ),
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search