import 'package:flutter/material.dart'; import 'package:file_picker_cross/file_picker_cross.dart'; import 'package:matrix/matrix.dart'; extension MatrixFileExtension on MatrixFile { void save(BuildContext context) => FilePickerCross(bytes).exportToStorage(fileName: name.split('/').last); MatrixFile get detectFileType { if (msgType == MessageTypes.Image) { return MatrixImageFile(bytes: bytes, name: name); } if (msgType == MessageTypes.Video) { return MatrixVideoFile(bytes: bytes, name: name); } if (msgType == MessageTypes.Audio) { return MatrixAudioFile(bytes: bytes, name: name); } return this; } String get sizeString { var size = this.size.toDouble(); if (size < 1000000) { size = size / 1000; size = (size * 10).round() / 10; return '${size.toString()} KB'; } else if (size < 1000000000) { size = size / 1000000; size = (size * 10).round() / 10; return '${size.toString()} MB'; } else { size = size / 1000000000; size = (size * 10).round() / 10; return '${size.toString()} GB'; } } }