Issue
This is my buildCountText function in flutter, where i am passing label and count as my arguments, I am using this function to show my count of followers in an app, but I don't know how to format my count if it's value is large in thousands or millions,I don't want to write the whole figure if its in million , I just want to write it as 1M(for example). but I don't know how to format it in that way.
buildCountText(String label, int count) {
return Container(
padding: EdgeInsets.only(top: 5, bottom: 6),
alignment: Alignment.centerLeft,
child: RichText(
text: TextSpan(
//text: label,
style: TextStyle(
fontFamily: "OpenSans", color: Theme.of(context).primaryColor),
children: <TextSpan>[
TextSpan(
text: label,
style: TextStyle(
fontFamily: "OpenSans", fontWeight: FontWeight.w500)),
TextSpan(
text:_isLoading?" ...": ' $count', style: TextStyle(fontWeight: FontWeight.bold)),
],
),
),
);
}
Solution
Use number formatter. https://pub.dev/documentation/intl/latest/intl/NumberFormat-class.html
var f = NumberFormat.compact();
print(f.format(100000)); //<= prints 100K
Answered By - LonelyWolf Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.