The code below represents a scrollable container. I would love to add/implement a scrollbar on one of the container's sides. I know this is possible with ListView/GridView but is it possible with SingleChildScrollView?
Thank you for the help!
Container(
padding: EdgeInsets.only(
bottom: 5, right: 15, left: 15, top: 5),
height: 100,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color.fromARGB(255, 250, 250, 250),
borderRadius: BorderRadius.circular(10),
border: Border.all(
width: 0, color: Colors.grey),
),
child: SingleChildScrollView(
child: Text('WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW',
style: TextStyle(color: Colors.black),
),
),
),
CodePudding user response:
Just wrap the widget with the Scrollbar
Scrollbar(
child: SingleChildScrollView(
child: Text(
'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it?It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using Content here, content here, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for lorem ipsum will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).',,
style: TextStyle(color: Colors.black),
),
),
),
CodePudding user response:
You have to have a bound on the right side for the text to flow downwards.. So you can create a sizedBox of specific width and add scroll bar in it
SizedBox(
width: MediaQuery.of(context).size.width,
height: 100,
child: ScrollBar(
child: SingleChildScrollView(
child: Flexible(
child: Text("Very long text to be added here"),
),
)
)
)