Reputation: 1491
I have a Text
widget inside Column
which is inside Padding
. And this Padding
is children of Row
which is the child of another Padding
.
So the structure would be: Container > Padding > Row > Padding > Column > Text
.
I tried to handle text overflow, but all of the overflow do not work. I tried to put the Container inside Expanded widget, but the view totally gone instead.
Here is my code :
Container(
decoration: constHomeBoxDecorationStyle,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0,
horizontal: 16.0,
),
child: Row(
children: [
SvgPicture.asset(
"assets/images/avatar.svg",
width: 48.0,
height: 48.0,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.w700,
),
),
Text(
name,
overflow: TextOverflow.clip,
maxLines: 1,
softWrap: false,
style: TextStyle(
fontSize: 24.0,
),
),
],
),
),
],
),
),
);
In the same page, I tried to build another Text Widget to test the overflow.
The structure is like this: SingleChildScrollView > Column > Padding > Column > Text
.
This one works perfectly fine (with same Text widget code from above.
Any idea why the first one does not work?
Edit: Add screenshot and output (A RenderFlex overflowed by 301 pixels on the right.
)
Exception :
The specific RenderFlex in question is: RenderFlex#ece9d relayoutBoundary=up18 OVERFLOWING
════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 301 pixels on the right.
The relevant error-causing widget was:
Row
lib
like a ListView.
The specific RenderFlex in question is: RenderFlex#ece9d relayoutBoundary=up18 OVERFLOWING:
creator: Row ← Padding ← DecoratedBox ← Container ← Column ← Padding ← Column ← Padding ←
_SingleChildViewport ← IgnorePointer-[GlobalKey#603bc] ← Semantics ← _PointerListener ← ⋯
parentData: offset=Offset(16.0, 8.0) (can use size)
constraints: BoxConstraints(0.0<=w<=296.7, 0.0<=h<=Infinity)
size: Size(296.7, 72.0)
direction: horizontal
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
textDirection: ltr
verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
════════════════════════════════════════════════════════════════════════════════════════════════════
Edit 2: The Answer (based on Piyush Dubey's answer)
Container(
decoration: constHomeBoxDecorationStyle,
padding: EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
leading: SvgPicture.asset(
"assets/images/avatar.svg",
width: 48.0,
height: 48.0,
),
title: Text(
name,
maxLines: 1,
style: TextStyle(
fontSize: 28.0,
fontWeight: FontWeight.w700,
),
),
subtitle: Text(
password,
style: TextStyle(
fontSize: 20.0,
),
),
),
)
Upvotes: 0
Views: 165
Reputation: 2793
You have to use Expanded
widget as the parent of the Padding
widget in the Row
widget as shown below:
Container(
decoration: constHomeBoxDecorationStyle,
padding: const EdgeInsets.symmetric( // <----- REMOVED PADDING WIDGET AS CONTAINER ALREADY HAS PADDING PROPERTY
vertical: 8.0,
horizontal: 16.0,
),
child: Row(
children: [
SvgPicture.asset(
"assets/images/avatar.svg",
width: 48.0,
height: 48.0,
),
Expanded(child: Padding( // <---------- HERE
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: TextStyle(
fontSize: 32.0,
fontWeight: FontWeight.w700,
),
),
Text(
name,
overflow: TextOverflow.clip,
maxLines: 1,
softWrap: false,
style: TextStyle(
fontSize: 24.0,
),
),
],
),
),),
],
),
);
Also, there is no need to create Padding
widget as the child of your Container
widget as Container
already has padding
property.
Upvotes: 1
Reputation: 306
You can use ListTile widget to achieve that,
ListTile(
leading: Icon(Icons.add),
title: Text('GFG title',textScaleFactor: 1.5,),
trailing: Icon(Icons.done),
subtitle: Text('This is subtitle'),
selected: true,
onTap: () {
setState(() {
txt='List Tile pressed';
});
},
),
Upvotes: 1