【问题标题】:how to find absolute path of asset(uploaded image) in flutter?如何在颤动中找到资产(上传的图像)的绝对路径?
【发布时间】:2021-12-03 20:27:13
【问题描述】:
 Asset asset = resultList![i]; 
     String fileName = asset.name!;
     final filePath = await FlutterAbsolutePath.getAbsolutePath(asset.identifier); 
     var f = File('${File(asset.identifier!).absolute.path}/$fileName');  
      
                 
      ```  print('FILE ABS :$filePath');```
   FILE ABS :/data/user/0/com.appname.com/cache/IMG_1634398462781.png
                
                             
                  print('FILE :$f');
                     FILE:File:'/content://media/external/images/media/18/JPEG_20211016_172650_1080214037652379427.jpg'
                    
                                  var file = File(filePath);
                                      var compressedFile;
                                      if (file.lengthSync() > 300000) {
                                        compressedFile = await FlutterImageCompress.compressWithFile(
                                          file.absolute.path,
                                          quality: 25,
                                        );
                                      }
                                      Network.MultipartFile multipartFile = await Network.MultipartFile.fromBytes(compressedFile != null ? compressedFile:file.readAsBytesSync(),filename: fileName);
                    
        

asset 是上传的图片
这个 FlutterAbsolutePath 不是空安全的,它是一个旧插件,请帮我解决这个问题..

【问题讨论】:

    标签: image flutter dart file-upload


    【解决方案1】:

    将此添加到您的 pubspec.yaml:

    flutter_absolute_path:
            git:
              url: https://github.com/ValeriusGC/flutter_absolute_path.git
    

    这是具有空安全支持的插件的一个分支。

    【讨论】:

    • - package:geocoder 错误:无法以可靠的 null 安全性运行,因为以下依赖项不支持 null 安全性:有没有办法使这个包为 null 安全?
    • @MohammedNiyaz 我找不到它的空安全版本,但如果你真的需要它,你可以尝试自己做。
    猜你喜欢
    • 2020-02-10
    • 1970-01-01
    • 2011-06-29
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 2019-02-20
    • 2016-08-10
    相关资源
    最近更新 更多