mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-23 09:40:40 +01:00
40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
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';
|
|
}
|
|
}
|
|
}
|