I am working on a Flutter app and I am trying to display a long text in a SliverList widget. I want to show the overflow text as dots so that the user knows that there is more text to read. I have tried using the Text widget with the maxLines and overflow properties set, but it doesn’t seem to be working in the SliverList. The text is still displayed without any truncation or dots. Can anyone help me figure out how to show the overflow text as dots in a SliverList widget in Flutter?
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
padding: EdgeInsets.symmetric(horizontal: screenWidth*0.05, vertical: screenHeight*0.01),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CircleAvatar(
backgroundImage: NetworkImage("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcScuQGyYbgV9HFyiunO9mF6_lnB6MYwcx6t3w&usqp=CAU"),
radius: screenWidth*0.08,
),
SizedBox(width: screenWidth*0.05,),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Adam John",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
),
),
SizedBox(height: 5.0),
Container(
padding: const EdgeInsets.all(1),
child: Text(
"hello! my name is adam john and i'm your new tariner",
maxLines: 1,
overflow: TextOverflow.fade,
style: TextStyle(
color: AppColors().darKShadowColor,
fontSize: 16.0,
),
),
),
],
),
Text(
"10:30pm",
style: TextStyle(
color: AppColors().darKShadowColor,
fontSize: 16.0,
),
),
],
),
);
},
childCount: 3,
),
),
5
Answers
Your Text is inside a Row, so it has an unbounded width.
Wrap your Text inside an
Expanded
and also set the overflow to:I’m Try to Solve Your Problem:
Update your code like this
Simply set the property of overflow inside your text widget to
This should do the work
so this is how your container will look like