Flutter:获取图像文件预览

问题描述 投票:0回答:1

我正在尝试获取类似于Google云端硬盘(在iOS和Android上)的布局的列表视图,如下所示。获得Cards的ListView是相当容易的。但是,我在获取图像的“预览”时遇到了麻烦。图像的预览是某个文档或图像的前100-200个像素。我执行此操作的一种方法是将一些图像保留在设备上,但希望有其他解决方案

ListView Card Image Preview

到目前为止,我的代码相对简单。

 @override
  Widget build(BuildContext context) {
    final screenHeight = MediaQuery.of(context).size.height;
    return Container(
        height: screenHeight/3,
        child: Card(
          clipBehavior: Clip.antiAliasWithSaveLayer,
          child: InkWell(
            child: Column(
              children: <Widget>[
                ListTile(
                  leading: Container(
                      child: ConstrainedBox(
                    constraints: BoxConstraints(
                      minWidth: 22,
                      minHeight: 22,
                      maxWidth: 33,
                      maxHeight: 33,
                    ),
                    child: Image.File(<some picture path>),
                  )),
                  title: Text(
                    'Title',
                    style: TextStyle(fontSize: screenHeight/3/10),
                  ),
                  // Picture preview
                  onTap: () => launch(<link>),
                  dense: false
                ),
              ],
            ),
          ),
        ));
  }
android ios flutter flutter-layout flutter-animation
1个回答
0
投票

我不知道有任何专门针对此问题的库来处理此问题;但是,您最好的选择是使用平台渠道,并使用[]

  1. QuickLook Thumbnail for iOS
  2. Thumbnail Utils on Android
  3. 以上链接中的iOS示例代码:

func generateThumbnailRepresentations() {

// Set up the parameters of the request.
guard let url = Bundle.main.url(forResource: "example", withExtension: "png") else {

    // Handle the error case.
    assert(false, "The URL can't be nil")
    return
}
let size: CGSize = CGSize(width: 60, height: 90)
let scale = UIScreen.main.scale

// Create the thumbnail request.
let request = QLThumbnailGenerator.Request(fileAt: url,
                                           size: size,
                                           scale: scale,
                                           representationTypes: .all)

// Retrieve the singleton instance of the thumbnail generator and generate the thumbnails.
let generator = QLThumbnailGenerator.shared
generator.generateRepresentations(for: request) { (thumbnail, type, error) in
    DispatchQueue.main.async {
        if thumbnail == nil || error != nil {
            // Handle the error case gracefully.
        } else {
            // Display the thumbnail that you created.
        }
    }
}

}

© www.soinside.com 2019 - 2024. All rights reserved.