charlesYun / photo_album_manager

This is the plug-in can quickly get album resources, support for android and iOS
MIT License
23 stars 12 forks source link

ios 11.1.2 and ios 13.4.1不正确 #5

Closed 120011676 closed 4 years ago

120011676 commented 4 years ago

ios 11.1.2 下分类查询不正确,图片都跑到视频里面了 ios 13.4.1 查询不到图片和视频

120011676 commented 4 years ago

已确认,ios不能分类多次调用

charlesYun commented 4 years ago

什么分类多次调用,能详细点吗

120011676 commented 4 years ago

@caoyunxiao var images = await PhotoAlbumManager.getDescAlbumImg(); var videos = await PhotoAlbumManager.getDescAlbumVideo();

结果不对

120011676 commented 4 years ago

1.窗口确认权限后,不能及时获取到图片 2.图片多些,方法慢,建议有什么异步可选择下

charlesYun commented 4 years ago

var images = await PhotoAlbumManager.getDescAlbumImg(); var videos = await PhotoAlbumManager.getDescAlbumVideo(); 我测试了,不存在结果不对的情况吧,图片是图片,视频是视频,你那边会乱? 有点慢是因为 HEIC格式的转码,否则flutter无法显示

charlesYun commented 4 years ago

可以考虑提前获取相册资源,用的时候直接取就行

120011676 commented 4 years ago

@caoyunxiao 切换到photo_manager了,快,丰富api

120011676 commented 4 years ago

ios、安卓图片视频多了(使用时3100张以上)显示会挂掉

charlesYun commented 4 years ago

你的建议已收到,这周我会发布一个优化版本

在2020年05月27日 20:33,Say.linotifications@github.com 写道:

ios图片视频多了显示会挂掉

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

120011676 commented 4 years ago

@caoyunxiao photo_manager ios浏览图片、视频占用空间急剧增大,是photo_album_manager的一个优势 https://github.com/CaiJingLong/flutter_photo_manager/issues/29

charlesYun commented 4 years ago

请更新最新版本1.1.2 https://pub.dev/packages/photo_album_manager 在2020年05月28日 21:55,Say.linotifications@github.com 写道:

@caoyunxiao photo_manager 浏览图片占用空间急剧增大,是photo_album_manager的一个优势 CaiJingLong/flutter_photo_manager#29

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

120011676 commented 4 years ago

@caoyunxiao ios测试 1.未达到速度预期 2.安装后第一次进入确认权限后,出不来内容 3.视频有报错现象

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following NoSuchMethodError was thrown building: The getter 'isNotEmpty' was called on null. Receiver: null Tried calling: isNotEmpty

When the exception was thrown, this was the stack:

0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)

1 PosixStyle.rootLength (package:path/src/style/posix.dart:32:14)

2 InternalStyle.getRoot (package:path/src/internal_style.dart:45:18)

3 new ParsedPath.parse (package:path/src/parsed_path.dart:43:22)

4 Context._parse (package:path/src/context.dart:1055:48)

... ════════════════════════════════════════════════════════════════════════════════════════════════════

import 'dart:io';
import 'package:path/path.dart';
import 'package:flutter/material.dart';
import 'package:photo_album_manager/photo_album_manager.dart';
import 'package:provider/provider.dart';
import 'package:qlink/booth/display.dart';
import 'package:qlink/common/upload.dart';
import 'package:qlink/image/fade_route.dart';
import 'package:qlink/image/image_preview.dart';
import 'package:qlink/local_upload/upload_file_model.dart';
import 'package:qlink/local_upload/uploaded.dart';
import 'package:qlink/state/current_pc.dart';

import 'local_file_util.dart';
import 'more_screen.dart';
import 'more_screen_image.dart';
import 'video_play.dart';

class Select extends StatefulWidget {
  @override
  State createState() => _SelectState();
}

class _SelectState extends State<Select> with SingleTickerProviderStateMixin {
  List _tabs = ["图片", "视频"];
  var _tabController;
  var _photos = [];
  var _videos = [];
  var _selectPhotos = {};
  final _photoMaxNumber = 4;
  var _uploading = false;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: _tabs.length, vsync: this);
    _loadResources();
  }

  _loadResources() {
    PhotoAlbumManager.getDescAlbum().then((albumModels) {
      albumModels.forEach((albumModel) {
        switch (albumModel.resourceType) {
          case 'image':
            _photos.add(albumModel);
            break;
          case 'video':
            _videos.add(albumModel);
            break;
        }
        setState(() {});
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('本地上传'),
        backgroundColor: Color(0xFF212C4A),
        actions: <Widget>[
          FlatButton(
            onPressed: () => Navigator.push(
                context, MaterialPageRoute(builder: (context) => Uploaded())),
            child: Text(
              '已上传',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ],
        bottom: TabBar(
          controller: _tabController,
          labelColor: Colors.blue,
          unselectedLabelColor: Colors.grey,
          tabs: _tabs.map((e) => Tab(text: e)).toList(),
        ),
      ),
      backgroundColor: Color(0xFF1A2036),
      body: TabBarView(
        controller: _tabController,
        children: _tabs.map((o) {
          switch (o) {
            case '图片':
              return Stack(
                children: <Widget>[
                  Column(
                    children: <Widget>[
                      Expanded(
                        child: GridView.builder(
                          padding: const EdgeInsets.all(1.0),
                          gridDelegate:
                          SliverGridDelegateWithFixedCrossAxisCount(
                            crossAxisCount: 3,
                            mainAxisSpacing: 1.0,
                            crossAxisSpacing: 1.0,
                          ),
                          itemCount: _photos.length,
                          itemBuilder: (BuildContext context, int index) {
                            AlbumModelEntity model = _photos[index];
                            return GestureDetector(
                              child: Card(
                                child: Stack(
                                  children: <Widget>[
                                    ConstrainedBox(
                                      constraints: BoxConstraints.expand(),
                                      child: Image.file(
                                        File(model.thumbPath ??
                                            model.originalPath),
                                        fit: BoxFit.cover,
                                      ),
                                    ),
                                    Offstage(
                                      child: Center(
                                        child: Icon(
                                          Icons.play_circle_outline,
                                          size: 40,
                                          color: Colors.white,
                                        ),
                                      ),
                                      offstage:
                                      !(model.resourceType == "video"),
                                    ),
                                    Positioned(
                                      top: 0,
                                      right: 0,
                                      child: IconButton(
                                        icon: _selectPhotos.containsKey(index)
                                            ? Icon(
                                          Icons.check_circle,
                                          color: Colors.blue,
                                        )
                                            : Icon(
                                          Icons.check_circle_outline,
                                          color: Colors.white,
                                        ),
                                        onPressed: () {
                                          setState(() {
                                            if (_selectPhotos
                                                .containsKey(index)) {
                                              _selectPhotos.remove(index);
                                            } else if (_selectPhotos.length <
                                                _photoMaxNumber) {
                                              _selectPhotos.putIfAbsent(
                                                  index, () => model);
                                            } else {
                                              Scaffold.of(context).showSnackBar(
                                                  SnackBar(
                                                      content: Text(
                                                          '最多选择$_photoMaxNumber张图片')));
                                            }
                                          });
                                        },
                                      ),
                                    )
                                  ],
                                ),
                              ),
                              onTap: () {
                                Navigator.of(context).push(FadeRoute(
                                  page: ImagePreview(
                                    images: _photos
                                        .map((o) => FileImage(
                                      File(o.originalPath),
                                    ))
                                        .toList(),
                                    index: index,
                                  ),
                                ));
                              },
                            );
                          },
                        ),
                      ),
                      Container(
                        height: 44,
                        width: double.infinity,
                        color: Color(0xFF212C4A),
                        child: Wrap(
                          alignment: WrapAlignment.spaceBetween,
                          children: <Widget>[
                            FlatButton(
                              onPressed: () {
                                if (_selectPhotos.length > 0) {
                                  Navigator.of(context).push(FadeRoute(
                                    page: ImagePreview(
                                      images: _selectPhotos.values
                                          .map((o) => FileImage(
                                        File(o.originalPath),
                                      ))
                                          .toList(),
                                      index: 0,
                                    ),
                                  ));
                                } else {
                                  Scaffold.of(context).showSnackBar(SnackBar(
                                    content: Text('没有选择图片'),
                                  ));
                                }
                              },
                              child: Text(
                                '预览',
                                style: const TextStyle(color: Colors.white),
                              ),
                            ),
                            FlatButton(
                              onPressed: () async {
                                if (_selectPhotos.length > 0) {
                                  setState(() {
                                    _uploading = true;
                                  });
                                  Future.wait(
                                      _selectPhotos.values.map((o) async {
                                        var result =
                                        await Upload.upload(UploadModel(
                                          file: File(o.originalPath),
                                          type: "image",
                                          viewPath: o.thumbPath ?? o.originalPath,
                                        ));
                                        DateTime dateTime = new DateTime.now();
                                        LocalFileUtil.write(
                                            [
                                              UploadFileModel(
                                                type: "image",
                                                localPath: o.originalPath,
                                                localThumbPath: o.thumbPath,
                                                uploadName: result.uploadName,
                                                uploadDatetime:
                                                '${dateTime.year.toString()}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}',
                                              )
                                            ],
                                            Provider.of<CurrentPC>(context,
                                                listen: false)
                                                .pc
                                                .id);
                                        EventBus().emit("uploadWrite", result);
                                        return result;
                                      })).then((os) {
                                    setState(() {
                                      _uploading = false;
                                    });
                                    Navigator.push(
                                      context,
                                      MaterialPageRoute(
                                        builder: (context) => os.length > 1
                                            ? MoreScreen(
                                          moreScreenImages: os
                                              .map((o) => MoreScreenImage(
                                            path: o.file.path,
                                            uploadName:
                                            o.uploadName,
                                          ))
                                              .toList(),
                                        )
                                            : Display(
                                          imageProvider: FileImage(
                                              File(os.first.file.path)),
                                          uploadName: os.first.uploadName,
                                        ),
                                      ),
                                    );
                                  });
                                } else {
                                  Scaffold.of(context).showSnackBar(SnackBar(
                                    content: Text('没有选择图片'),
                                  ));
                                }
                              },
                              child: Text(
                                '上传(${_selectPhotos.length}/$_photoMaxNumber)',
                                style: const TextStyle(color: Colors.blue),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                  Offstage(
                    offstage: !_uploading,
                    child: Container(
                      alignment: Alignment.center,
                      color: Color(0x00000000),
                      child: Container(
                        padding: const EdgeInsets.all(25),
                        decoration: BoxDecoration(
                          color: Color(0xaa000000),
                          borderRadius: BorderRadius.circular(5),
                        ),
                        child: SizedBox(
                          width: 50.0,
                          height: 50.0,
                          child: CircularProgressIndicator(
                            strokeWidth: 5.0,
                            backgroundColor: Colors.blue,
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              );
            case '视频':
              return ListView.separated(
                  padding: const EdgeInsets.all(5.0),
                  itemBuilder: (context, index) {
                    AlbumModelEntity model = _videos[index];
                    var _uploading = Upload.contains(model.originalPath);
                    return Row(
                      children: <Widget>[
                        GestureDetector(
                          child: Stack(
                            alignment: Alignment.center,
                            children: <Widget>[
                              Container(
                                width: 80,
                                height: 80,
                                child: Image.file(
                                  File(model.thumbPath ?? model.originalPath),
                                  fit: BoxFit.cover,
                                ),
                              ),
                              Offstage(
                                offstage: model.resourceType == "video"
                                    ? false
                                    : true,
                                child: Center(
                                  child: Icon(
                                    Icons.play_circle_outline,
                                    size: 40,
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                            ],
                          ),
                          onTap: () {
                            Navigator.of(context).push(MaterialPageRoute(
                                builder: (context) =>
                                    VideoPlay.file(File(model.originalPath))));
                          },
                        ),
                        Expanded(
                          child: Container(
                            alignment: Alignment.centerLeft,
                            padding: const EdgeInsets.all(10),
                            child: Text(
                              basename(model.originalPath),
                              style: const TextStyle(
                                color: Colors.white,
                                fontSize: 14,
                              ),
                            ),
                          ),
                        ),
                        SizedBox(
                          child: OutlineButton(
                            onPressed: () {
                              if (!_uploading) {
                                setState(() {
                                  _uploading = true;
                                });
                                Upload.upload(UploadModel(
                                  file: File(model.originalPath),
                                  type: "video",
                                  viewPath:
                                  model.thumbPath ?? model.originalPath,
                                  key: model.originalPath,
                                )).then((data) {
                                  DateTime dateTime = new DateTime.now();
                                  LocalFileUtil.write(
                                      [
                                        UploadFileModel(
                                          type: "video",
                                          localPath: model.originalPath,
                                          localThumbPath: model.thumbPath,
                                          uploadName: data.uploadName,
                                          uploadDatetime:
                                          '${dateTime.year.toString()}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')} ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}',
                                        )
                                      ],
                                      Provider.of<CurrentPC>(context,
                                          listen: false)
                                          .pc
                                          .id);
                                  try {
                                    EventBus().emit("uploadWrite", data);
                                  } catch (e) {
                                    print('$e');
                                  }
                                  setState(() {
                                    _uploading = false;
                                  });
                                });
                              }
                            },
                            borderSide: BorderSide(
                              color: _uploading
                                  ? Colors.grey
                                  : const Color(0xff529EFE),
                            ),
                            child: Text(
                              _uploading ? '上传中...' : '上传',
                              style: TextStyle(
                                color: _uploading
                                    ? Colors.grey
                                    : const Color(0xff529EFE),
                                fontSize: 14,
                              ),
                            ),
                          ),
                        ),
                      ],
                    );
                  },
                  separatorBuilder: (context, index) {
                    return Divider(
                      color: Color(0xff212C4A),
                    );
                  },
                  itemCount: _videos.length);
            default:
              return Container();
          }
        }).toList(),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
charlesYun commented 4 years ago

首先你这个使用全部相册资源,需要考虑预加载,否则速度起不来。少数资源不存在这种问题,建议在使用之前先执行PhotoAlbumManager.getDescAlbum(),它内部有缓存机制,在你真正需要用的时候,再重新执行,速度应该能达到你的预期 还有就是originalPath 字段,不一定有值的,由于苹果机制,原始资源可能在iCloud,需要下载,内部已经提供了相关的api,建议断点调试看看。