Issue
- I am trying to create a list view that contains 10 data, in each item there four widgets that wraps inside a row.
- First i inserted a circle image widget, in next I added expanded widget to divide the text widgets equally.
- Almost, I have achieved but i found difficulty in ellipsis the text.
Code
class EmailPage extends StatefulWidget {
@override
_EmailPageState createState() => _EmailPageState();
}
class _EmailPageState extends State<EmailPage> {
GlobalKey _keyRed = GlobalKey();
var name = "Adellena Jacksonnnnnnnnnnnnnnnnnnnnnnnnnnnn";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0.0,
backgroundColor: greenColor,
title: const Text('Inbox'),
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.edit),
onPressed: () => Navigator.of(context).pop(null),
),
],
),
body: SizedBox(
width: MediaQuery.of(context).size.width,
child: ListView.builder(
shrinkWrap: true,
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: new Row(
children: <Widget>[
SizedBox(
width: 30,
height: 30,
child: CircleAvatar(
backgroundColor: Colors.brown.shade800),
),
Expanded(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
flex: 4,
child: Container(
child: new Text(
name,
overflow: TextOverflow.ellipsis,
softWrap: false,
style: TextStyle(fontSize: 14),
),
),
),
new Expanded(
flex: 3,
child: new Text(
"&14215",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 12),
),
),
new Expanded(
flex: 3,
child: new Text(
"1000 min ago",
textAlign: TextAlign.end,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14),
),
),
],
),
),
],
),
);
}),
));
}
}
Screenshot 1
When we remove
overflow: TextOverflow.ellipsis
in the text widget look like this [Screenshot 2]
Screenshot 2
In above image i didn't get the full text "AdellenaJacksonnnnnnnnn ", but expanded restrict the widget how many flex can be shown in it. Problem is ellipsis not working as expected
Note : When i remove the space in the string var name = "AdellenaJacksonnnnnnnnn";
like this ellipsis working fine
Solution
overflow: TextOverflow.fade
did the trick for me.
Answered By - georkings
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.