| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import 'dart:io';
- import 'dart:typed_data';
- import 'package:wechat_assets_picker/wechat_assets_picker.dart';
- class AssetInfo {
- final String id;
- final int width;
- final int height;
- final int? duration;
- final int orientation;
- final int typeInt;
- final int? createDateSecond;
- final DateTime createDateTime;
- final DateTime modifiedDateTime;
- final String? title;
- final String? relativePath;
- final String? localPath;
- final String? filePath;
- final String? thumbFilePath;
- int? size;
- AssetInfo({
- required this.id,
- required this.width,
- required this.height,
- this.duration,
- required this.orientation,
- required this.typeInt,
- this.createDateSecond,
- required this.createDateTime,
- required this.modifiedDateTime,
- this.localPath,
- this.title,
- this.relativePath,
- this.filePath,
- this.thumbFilePath,
- this.size,
- });
- // 从 AssetEntity 创建
- factory AssetInfo.fromAssetEntity(
- AssetEntity entity, String filePath, String thumbFilePath) {
- return AssetInfo(
- id: entity.id,
- width: entity.width,
- height: entity.height,
- duration: entity.duration,
- orientation: entity.orientation,
- typeInt: entity.typeInt,
- createDateSecond: entity.createDateSecond,
- createDateTime: entity.createDateTime,
- modifiedDateTime: entity.modifiedDateTime,
- title: entity.title,
- relativePath: entity.relativePath,
- filePath: filePath,
- thumbFilePath: thumbFilePath,
- );
- }
- // 转换为 JSON
- Map<String, dynamic> toJson() => {
- 'id': id,
- 'width': width,
- 'height': height,
- 'duration': duration,
- 'orientation': orientation,
- 'typeInt': typeInt,
- 'createDateSecond': createDateSecond,
- 'createDateTime': createDateTime.toIso8601String(),
- 'modifiedDateTime': modifiedDateTime.toIso8601String(),
- 'title': title,
- 'relativePath': relativePath,
- 'localPath': localPath,
- 'file': filePath,
- 'thumbFile': thumbFilePath,
- };
- // 从 JSON 创建
- factory AssetInfo.fromJson(Map<String, dynamic> json) => AssetInfo(
- id: json['id'] as String,
- width: json['width'] as int,
- height: json['height'] as int,
- duration: json['duration'] as int,
- orientation: json['orientation'] as int,
- // isAll: json['isAll'] as bool,
- typeInt: json['typeInt'] as int,
- createDateSecond: json['createDateSecond'] as int?,
- createDateTime: DateTime.parse(json['createDateTime'] as String),
- modifiedDateTime: DateTime.parse(json['modifiedDateTime'] as String),
- title: json['title'] as String?,
- relativePath: json['relativePath'] as String?,
- localPath: json['localPath'] as String?,
- filePath: json['filePath'] as String?,
- thumbFilePath: json['thumbFilePath'] as String?,
- );
- // MARK: - To Do
- // 转换为 AssetEntity
- Future<AssetEntity?> toAssetEntity() async {
- return await AssetEntity.fromId(id);
- }
- // 获取文件对象
- File get file => File(filePath!);
- // 获取缩略图数据
- Future<Uint8List?> get thumbnailData async {
- File thumbFile = File(thumbFilePath!);
- try {
- if (await thumbFile.exists()) {
- return await thumbFile.readAsBytes();
- }
- return null;
- } catch (e) {
- print('获取缩略图失败: $e');
- return null;
- }
- }
- }
|