You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7KB

  1. import 'package:farm_tpf/custom_model/Media.dart';
  2. import 'package:farm_tpf/utils/const_common.dart';
  3. import 'package:flutter_cache_manager/flutter_cache_manager.dart';
  4. import 'package:mime/mime.dart';
  5. class UtilAction {
  6. static Future<List<Media>> cacheFiles(String existedMedias) async {
  7. var medias = List<Media>();
  8. var mediaPaths = existedMedias.split(";");
  9. for (int i = 0; i < mediaPaths.length; i++) {
  10. var tempFile = await DefaultCacheManager()
  11. .getSingleFile(ConstCommon.baseImageUrl + mediaPaths[i]);
  12. print(tempFile.path);
  13. var isVideo = lookupMimeType(tempFile.path) == "video/mp4";
  14. print("file type: " + lookupMimeType(tempFile.path));
  15. Media media = Media()
  16. ..pathFile = tempFile.path
  17. ..isVideo = isVideo;
  18. medias.add(media);
  19. }
  20. return medias;
  21. }
  22. static num convertUnit({num inputValue, String oldUnit, String newUnit}) {
  23. num result = inputValue;
  24. if (newUnit.isEmpty || newUnit == oldUnit) {
  25. return result;
  26. }
  27. if (oldUnit == "kg" || oldUnit == "l") {
  28. result = result * 1000;
  29. } else if (oldUnit == "g" || oldUnit == "ml") {
  30. result = result / 1000;
  31. } else if (oldUnit == "m") {
  32. if (newUnit == "cm") {
  33. result = result * 100;
  34. } else if (newUnit == "mm") {
  35. result = result * 1000;
  36. }
  37. } else if (oldUnit == "cm") {
  38. if (newUnit == "m") {
  39. result = result / 100;
  40. } else if (newUnit == "mm") {
  41. result = result * 10;
  42. }
  43. } else if (oldUnit == "mm") {
  44. if (newUnit == "m") {
  45. result = result / 1000;
  46. } else if (newUnit == "cm") {
  47. result = result / 10;
  48. }
  49. }
  50. return result;
  51. }
  52. }