feat: Added file size in proper format

This commit is contained in:
Deven Joshi
2020-12-11 19:54:02 +05:30
parent 18781201e3
commit c487ce92d0
+15 -1
View File
@@ -99,7 +99,7 @@ class _FileAttachmentState extends State<FileAttachment> {
height: 3.0,
),
Text(
'${widget.attachment.extraData['file_size'] ?? 'N/A'} bytes',
'${_getSizeText(widget.attachment.extraData['file_size'])}',
style: TextStyle(
color: Colors.black.withOpacity(0.5),
fontSize: 14.0,
@@ -284,4 +284,18 @@ class _FileAttachmentState extends State<FileAttachment> {
break;
}
}
String _getSizeText(int bytes) {
if (bytes == null) {
return 'Size N/A';
}
if (bytes <= 1000) {
return '${bytes} bytes';
} else if (bytes <= 100000) {
return '${(bytes / 1000).toStringAsFixed(2)} KB';
} else {
return '${(bytes / 1000000).toStringAsFixed(2)} MB';
}
}
}