textoverflow inside custom list tile - flutter

I have a ListView and I want to display the items in my custom list tile, the problem is that my text oveflow the tile, i want to add TextOverflow.ellipsis but it doesn't work.
Here's my code:
return Expanded(
child: ListView.builder(
itemCount: songss.length,
itemBuilder: (context, index) {
Song song = songss[index];
return Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: kPrimaryColor))),
margin: const EdgeInsets.only(left: 16.0),
child: InkWell(
child: Column(
children: <Widget>[
SizedBox(height: 12.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Text("${index + 1}",
style: Theme.of(context).textTheme.subtitle2),
SizedBox(width: 16.0),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
song.title,
style: Theme.of(context).textTheme.subtitle1,
overflow: TextOverflow.ellipsis, //Here i want to handle overflow
),
Text(_getSongDuration(song.duration),
style: Theme.of(context).textTheme.subtitle2),
],
),
],
),
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: Row(
children: <Widget>[
IconButton(
onPressed: () => null,
icon: Icon(Icons.favorite_border),
),
GestureDetector(
onTapDown: (TapDownDetails details) =>
null,
child: Icon(Icons.more_horiz),
),
],
),
)
],
),
SizedBox(height: 12.0),
],
),
),
);
},
),
);
I tried using expanded and flex but it gives me error.
Do you know how to solve it?

Give height,width to the Parent Widget of Text widget and then wrap Text with Expanded
Your error will be solved as expanded/flex need some max parent size to take space from.

I've actualy managed to solve the problem.
return Expanded(
child: ListView.builder(
itemCount: songss.length,
itemBuilder: (context, index) {
Song song = songss[index];
return Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: kPrimaryColor))),
margin: const EdgeInsets.only(left: 16.0),
child: InkWell(
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Text("${index + 1}",
style: Theme.of(context).textTheme.subtitle2),
SizedBox(width: 16.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
song.title,
style: Theme.of(context).textTheme.subtitle1,
overflow: TextOverflow.ellipsis,
),
Text(_getSongDuration(song.duration),
style: Theme.of(context).textTheme.subtitle2),
],
),
),
IconButton(
onPressed: () => null,
icon: Icon(Icons.favorite_border),
),
GestureDetector(
onTapDown: (TapDownDetails details) => null,
child: Icon(Icons.more_horiz),
),
],
),
),
);
},
),
);
I've just rewrote the whole list, removing one or two rows.
So i'm gonna answer the question, thank you for your help tho.

Related

How to align expanded widgets in a row

Why does the 1st two work but not the 3rd?? what's the alternative to add vertical divider with height that stretch to the max height of the row?
These 2 works
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
child: Text('Kicukiro'),
),
Container(width: 1,color: Colors.black,height: double.infinity,),
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text('Kicukiro'),
)
],
)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
child: Text('Kicukiro'),
),
),
// Container(width: 1,color: Colors.black,height: double.infinity,),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text('Kicukiro'),
),
)
],
)
this does not work
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
child: Text('Kicukiro'),
),
),
Container(width: 1,color: Colors.black,height: double.infinity,),
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text('Kicukiro'),
),
)
],
)
Test this and it will work
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
child: const Text("Kicukiro", style: TextStyle(fontSize: 52),)),
),
Container(color:Colors.black, width: 1),
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: const Text("Kicukiro", style: TextStyle(fontSize: 52),)),
),
],
),
),
In the last screenshot please add the Container under an Expanded widget. Use children property under Row widget.
Here is an example code
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
flex: 5,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: Text(
'This is question',
style: TextStyle(
fontSize: 25.0,
color: Colors.white,
),
),
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.all(10.0),
child: FlatButton(
//textColor: Colors.white,
color: Colors.green,
child: Text(
'True',
style: TextStyle(color: Colors.white, fontSize: 20.0),
),
onPressed: () {},
),
)),
Expanded(
child: Padding(
padding: EdgeInsets.all(10.0),
child: FlatButton(
//textColor: Colors.white,
color: Colors.red,
child: Text(
'False',
style: TextStyle(color: Colors.white, fontSize: 20.0),
),
onPressed: () {},
),
)),
]
The third is true, in fact, its existence in an SingleChildScrollView has created a problem
It is fixed by putting SizedBox in Row and giving it height
The reason for this problem is the size of the height of the container, which is determined by double.infinity and due to its presence in an SingleChildScrollView, it continues indefinitely and an error was created.
SingleChildScrollView(
child: SizedBox(
height: 250,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(child: Container(child: Text("Kicukiro"))),
Container(
width: 1,color: Colors.black,height: double.infinity,
),
Expanded(child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Text("Kicukiro"))),
],
),
),
),

How to use show icons into expand widget like the block of github in flutter with

There're two questions.
01.
I want to show more rows of icons with one List only. As you see from Fig3, I'm using three rows in Expand widget, in Card, and each row has the corresponding List. I think it was not so nice to build like this way.
02.
Which widget will be more suitable to build blocks view Github in Flutter?
Fig1.
Fig2.
Fig3.
body: Container(
child: Column(
children: <Widget>[
Text('TrahsCollection',
style: const TextStyle(
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 13),
),
Flexible(
child: ListView.builder(
itemCount: _item.length,
itemBuilder: (BuildContext context, int index) {
final String item = _item[index];
final MaterialColor = Colors.blue;
return Container(
margin: const EdgeInsets.only(top: 5.0),
child: Card(
margin: EdgeInsets.all(5),
elevation: 10,
child: Row(
children: <Widget>[
Expanded(
flex:2,
child: ListTile(
leading: CircleAvatar(
backgroundColor: Colors.amber[300],
child: Text("Pop"),
),
),
),
const Expanded(
flex:3,
child: ListTile(
title: Text("Title", style: TextStyle(fontSize: 20),),
subtitle: Text("SubTitle"),
),
),
Expanded(
flex:3,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(2.0),
child: Row(
children: scoreKeeper,
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Row(
children: scoreKeeper,
),
),
Padding(
padding: const EdgeInsets.all(2.0),
child: Row(
children: scoreKeeper,
),
),
],
),
),
],
),
)
);
},
),
)
],
),
),
Your building approach is okey, but you should move your peaces of code to separated widgets
You can use GridView

There are constantly overflows on the card structure

I just started flutter. I tried to make a card structure but I think it is quite wrong. I could never fix it. I am using Gridview extend. In this way, the column numbers change dynamically as the screen gets smaller or larger. but i keep getting overflow error what should i do.
var response = sepet.itemsCount[item.name];
return SizedBox(
child: Padding(
padding: EdgeInsets.all(0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0))),
child: InkWell(
customBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
onTap: () {},
child: Column(
children: <Widget>[
ListTile(
title: Text(item.name ?? ''),
subtitle: Text(item.defaultPrice.toString() + '\$'),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
countChanger(sepet, false, item),
Padding(
padding: EdgeInsets.only(left: 8.0, right: 8.0),
child: Text(
response != null ? response.toString() : '0',
style: TextStyle(fontSize: 18.0),
),
),
countChanger(sepet, true, item),
],
),
ButtonTheme(
height: 25,
minWidth: 25,
child: ElevatedButton(
onPressed: () {
!isAdded
? sepet.sepeteEkle(item)
: sepet.deleteItem(item);
},
style: ElevatedButton.styleFrom(
primary: !isAdded
? Colors.teal
: Colors.red,
),
child: Text(!isAdded ? 'Ekle' : 'Çıkar'),
),
),
],
),
)
],
),
),
),
],
),
),
);
My gridview extend structure is like this
child: GridView.extent(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
maxCrossAxisExtent: 250.0,
crossAxisSpacing: 20.0,
mainAxisSpacing: 20.0,
children: List.generate(foods!.length, (index) {
return itemCard(foods[index].menuItem ?? MenuItem(), value);
}),
The question you need to answer is what would you like to happen if the width of that card is so small? Do you want a different arrangement of those elements? If you do decide on what that would look like and check the constraint with LayoutBuilder Or the whole screen width with MediaQuery whatever you feel is best. You could also make that bit scroll horizontally by using SingleChildScrollView. This is a design decision. You must image what things look like when screen size changes, and be as deliberate as possible with the responsiveness rather then to just try to find some magic widget which we are all guilty of doing sometimes.
Try below code hope its helpful to you I have try similar to your code and add your widgets in Expanded or Flexible Widgets.
flexible widgets
expanded Widgets
GridView.builder(
padding: const EdgeInsets.all(8),
itemCount: 4,
itemBuilder: (ctx, i) {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text('data'),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
margin: EdgeInsets.all(10),
height: 35.0,
width: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.grey,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
InkWell(
child: Icon(Icons.remove, color: Colors.green),
onTap: () {},
),
Spacer(),
Text(
'0',
style: Theme.of(context)
.textTheme
.subtitle2!
.copyWith(fontSize: 16.0),
),
Spacer(),
InkWell(
child: Icon(
Icons.add,
color: Colors.green,
),
onTap: () {},
),
],
),
),
),
Expanded(
child: ElevatedButton(
onPressed: () {},
child: Text(
'Sub Total',
style: TextStyle(
fontSize: 15,
),
),
),
),
],
),
],
),
);
},
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 170.0,
mainAxisExtent: 93,
),
),
Your Result screen like->

Flutter: Place a particular widget in a row at center

How to place the "question mark" at center of row?
Expected result is "?" are all at center regardless of the values on left/right.
body: ListView.builder(
itemCount: testList.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.green,
child: Text(testList[index].n1.toString(), style: TextStyle(fontSize: 80,)),
),
Container(
color: Colors.red,
child: Text(testList[index].x, style: TextStyle(fontSize: 80,)),
),
Container(
color: Colors.green,
child: Text(testList[index].n2.toString(), style: TextStyle(fontSize: 80, )),
),
],
),
Text('>'),
Text('<'),
Text('='), //
],
),
);
}),
You can use row and Expanded with flex widget to achieve your desire output.
Following minimal code help you more.
Card(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
flex: 1,
child: Row(
children: [
Expanded(child: Container()),
Container(
color: Colors.green,
child: Text('10',
style: TextStyle(
fontSize: 80,
)),
),
],
),
),
Container(
color: Colors.red,
child: Text("?",
style: TextStyle(
fontSize: 80,
)),
),
Expanded(
flex: 1,
child: Row(
children: [
Container(
color: Colors.green,
child: Text('100',
style: TextStyle(
fontSize: 80,
)),
),
Expanded(child: Container()),
],
),
),
],
),
Text('>'),
Text('<'),
Text('='), //
],
),
)

TextOverFlow.ellipsis in Widget Text not work

my widget text Wrap inside Expanded, row, and Column
return Container(
child: Expanded(
flex: 9,
child: GestureDetector(
onTap: () {
// .......
},
child: Container(
color: Colors.transparent,
child: Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 15, bottom: 15),
child: Container(
width: 2,
color: Color(0XFF2B9FDC),
)),
Padding(
padding: EdgeInsets.only(left: 15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text( item.name,
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
Text(item.catgeory),
Text(item.price,
style: TextStyle(color: Colors.red),
),
],
),
),
],
),
),
),
),
);
I got error : Another exception was thrown: A RenderFlex overflowed by 7.3 pixels on the right.
AnyOne can help?
Just wrap your container with Expanded and use flex property as per your design and let me know its working or not
return Expanded(
child: Container(
child: GestureDetector(
onTap: () {
// .......
},
child: Container(
color: Colors.transparent,
child: Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 15, bottom: 15),
child: Container(
width: 2,
color: Color(0XFF2B9FDC),
)),
Padding(
padding: EdgeInsets.only(left: 15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text( item.name,
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
Text(item.catgeory),
Text(item.price,
style: TextStyle(color: Colors.red),
),
],
),
),
],
),
),
),
),
);
Change this:
Text(
item.name,
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
into this:
Text(
item.name,
softWrap : true,
maxLines: 2,
),
softWrap → bool
Whether the text should break at soft line breaks