|
- import 'package:farm_tpf/custom_model/Media.dart';
- import 'package:farm_tpf/utils/const_common.dart';
- import 'package:flutter_cache_manager/flutter_cache_manager.dart';
- import 'package:mime/mime.dart';
-
- class UtilAction {
- static Future<List<Media>> cacheFiles(String existedMedias) async {
- var medias = List<Media>();
- var mediaPaths = existedMedias.split(";");
- for (int i = 0; i < mediaPaths.length; i++) {
- var tempFile = await DefaultCacheManager()
- .getSingleFile(ConstCommon.baseImageUrl + mediaPaths[i]);
- print(tempFile.path);
- var isVideo = lookupMimeType(tempFile.path) == "video/mp4";
- print("file type: " + lookupMimeType(tempFile.path));
- Media media = Media()
- ..pathFile = tempFile.path
- ..isVideo = isVideo;
- medias.add(media);
- }
- return medias;
- }
-
- static num convertUnit({num inputValue, String oldUnit, String newUnit}) {
- num result = inputValue;
- if (newUnit.isEmpty || newUnit == oldUnit) {
- return result;
- }
- if (oldUnit == "kg" || oldUnit == "l") {
- result = result * 1000;
- } else if (oldUnit == "g" || oldUnit == "ml") {
- result = result / 1000;
- } else if (oldUnit == "m") {
- if (newUnit == "cm") {
- result = result * 100;
- } else if (newUnit == "mm") {
- result = result * 1000;
- }
- } else if (oldUnit == "cm") {
- if (newUnit == "m") {
- result = result / 100;
- } else if (newUnit == "mm") {
- result = result * 10;
- }
- } else if (oldUnit == "mm") {
- if (newUnit == "m") {
- result = result / 1000;
- } else if (newUnit == "cm") {
- result = result / 10;
- }
- }
- return result;
- }
- }
|