fluttercandies / flutter_photo_manager

A Flutter plugin that provides images, videos, and audio abstraction management APIs without interface integration, available on Android, iOS, macOS and OpenHarmony.
https://pub.dev/packages/photo_manager
Apache License 2.0
697 stars 317 forks source link

About DecoderCallback cannot found error( Type 'DecoderCallback' not found.) #1021

Closed CaiJingLong closed 1 year ago

CaiJingLong commented 1 year ago

Use version 3.0.0-dev.1 first.

If you use the newest flutter stable version (3.16.0), you need use photo_manager version 3.0.0-dev.1, and the stable version will be published a few days.


This API has been officially removed by flutter. I plan to release version 3.0 in the future and remove the related API, and release an independent package to inherit flutter's ImageProvider. Until then, I recommended use stable of flutter SDK first.


If your log have next error:

Error (Xcode): ../../../.pub-cache/hosted/pub.dev/photo_manager-2.7.2/lib/src/internal/image_provider.dart:71:5: Error: Type 'DecoderCallback' not found.

If it is not any other reports next week, I will push the release version instead of the dev version.

imdtushar commented 1 year ago

../../.pub-cache/hosted/pub.dev/photo_manager-2.8.1/lib/src/internal/image_provider.dart:71:5: Error: Type 'DecoderCallback' not found. DecoderCallback decode, // ignore: deprecated_member_use

still issue with latest Version 
Ben1980 commented 1 year ago

Upgraded Flutter today to stable 3.16 and got the same error. When is photo_manager getting to stable 3.0.0?

xacaciax commented 1 year ago

Same issue here

den0206 commented 1 year ago

@Ben1980 @xacaciax

Temporary fix.

// if you use
dependencies:
  wechat_assets_picker: ^8.9.0-dev.1

dependency_overrides: 
  photo_manager: ^3.0.0-dev.2

I'm waiting for it to be updated to stable version :)

shinesincere commented 1 year ago

After updating with the temporary fix mentioned above, now I'm getting the error, "The method 'AssetEntityImage' isn't defined".

CaiJingLong commented 1 year ago

After updating with the temporary fix mentioned above, now I'm getting the error, "The method 'AssetEntityImage' isn't defined".

Read the doc to know how to migrate to 3.x of photo_manager.

xacaciax commented 1 year ago

Adding this to pubspec.yaml worked as temporary fix, ty @den0206

dependency_overrides: 
  photo_manager: ^3.0.0-dev.2
abdibrokhim commented 11 months ago

@Ben1980 @xacaciax

Temporary fix.

// if you use
dependencies:
  wechat_assets_picker: ^8.9.0-dev.1

dependency_overrides: 
  photo_manager: ^3.0.0-dev.2

I'm waiting for it to be updated to stable version :)

Hi, worked for also, thank you a lot)

joytechexordium commented 11 months ago

Please publish this on stable channel, as we are not able to use latest stable version of flutter in our project. Above mention don't work because there is one more package on top of wechat_assets_picker that we are using.

Thank you

Mounix99 commented 10 months ago

For those who get some kind of The method 'AssetEntityImage' isn't defined or similar errors, don't forget to call flutter clean

ksb2311 commented 10 months ago

For those who get some kind of The method 'AssetEntityImage' isn't defined or similar errors, don't forget to call flutter clean

Changed package to photo_manager: ^3.0.0-dev.5

Did flutter clean

But still getting The method 'AssetEntityImage' isn't defined error

drexqq commented 10 months ago

@ksb2311

AssetEntityImage is provided in the photo_manager_image_provider package.

For those who get some kind of The method 'AssetEntityImage' isn't defined or similar errors, don't forget to call flutter clean

Changed package to photo_manager: ^3.0.0-dev.5

Did flutter clean

But still getting The method 'AssetEntityImage' isn't defined error

https://pub.dev/packages/photo_manager/versions/3.0.0-dev.5

image
babbage commented 10 months ago

I am so glad we have the -dev version that we can pin as a dependency override, but given it was predicted in early November that the stable version would be published in "a few days", it would be great if this package could reach that point. Thanks for all the work that you do!

AlexV525 commented 10 months ago

Sorry about not publishing a new stable version. We're still occupied by works in our life, which there are some TO-DO with the manager and the picker that might need to solve before we can push this. Glad everyone here knows how to use dev versions. Please allow us to take a bit longer to deal with it.

Ben1980 commented 10 months ago

No worries, I'm glad about the plugin and looking forward whenever it's ready.

faizanBetaTech commented 9 months ago

I solved the issue , you don't need to downgrade photo manager or your flutter SDK , you just need to update the imageprovider.dart file from package photo manager : 2.8.1 , And here is the updated code of imageprovider.dart file

``` // Copyright 2018 The FlutterCandies author. All rights reserved. // Use of this source code is governed by an Apache license that can be found // in the LICENSE file. import 'dart:async'; import 'dart:io'; import 'dart:typed_data' as typed_data; import 'dart:ui' as ui; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import '../types/entity.dart'; import '../types/thumbnail.dart'; import 'constants.dart'; import 'enums.dart'; final _providerLocks = >{}; /// The [ImageProvider] that handles [AssetEntity]. /// /// Only support [AssetType.image] and [AssetType.video], /// others will throw errors during the resolving. /// /// If [isOriginal] is true: /// * Fetch [AssetEntity.thumbnailData] for [AssetType.video]. /// * Fetch [AssetEntity.file] and convert to bytes for HEIF(HEIC) images. /// * Fetch [AssetEntity.originBytes] for images. /// Else, fetch [AssetEntity.thumbnailDataWithOption] with the given /// [thumbnailSize] and the [thumbnailFormat]. /// /// {@template remove_in_3_0} /// *** /// Because the Flutter version changes, there will be compatibility issues. /// This class is expected to be removed in 3.0 and become a separate package. /// *** /// {@endtemplate} @immutable class AssetEntityImageProvider extends ImageProvider { const AssetEntityImageProvider( this.entity, { this.isOriginal = true, this.thumbnailSize = PMConstants.vDefaultGridThumbnailSize, this.thumbnailFormat = ThumbnailFormat.jpeg, }) : assert( isOriginal || thumbnailSize != null, "thumbSize must not be null when it's not original", ); /// {@macro photo_manager.AssetEntity} final AssetEntity entity; /// Choose if original data or thumb data should be loaded. /// 选择载入原数据还是缩略图数据。 final bool isOriginal; /// Size for thumb data. /// 缩略图的大小。 final ThumbnailSize? thumbnailSize; /// {@macro photo_manager.ThumbnailFormat} final ThumbnailFormat thumbnailFormat; /// File type for the image asset, use it for some special type detection. /// 图片资源的类型,用于某些特殊类型的判断。 ImageFileType get imageFileType => _getType(); @override ImageStreamCompleter loadImage( AssetEntityImageProvider key, ImageDecoderCallback decode) { return MultiFrameImageStreamCompleter( codec: _loadAsync(key, decode), scale: 1.0, debugLabel: '${key.entity.runtimeType}-' '${key.entity.id}-' '${isOriginal ? 'origin-' : ''}' '${isOriginal ? '' : '$thumbnailFormat'}', informationCollector: () { return [ DiagnosticsProperty('Image provider', this), DiagnosticsProperty('Image key', key), ]; }, ); } @override Future obtainKey(ImageConfiguration configuration) { return SynchronousFuture(this); } Future _loadAsync( AssetEntityImageProvider key, ImageDecoderCallback decode, // ignore: deprecated_member_use ) { if (_providerLocks.containsKey(key)) { return _providerLocks[key]!.future; } final lock = Completer(); _providerLocks[key] = lock; Future(() async { try { assert(key == this); if (key.entity.type == AssetType.audio || key.entity.type == AssetType.other) { throw UnsupportedError( 'Image data for the ${key.entity.type} is not supported.', ); } // Define the image type. final ImageFileType type; if (key.imageFileType == ImageFileType.other) { // Assume the title is invalid here, try again with the async getter. type = _getType(await key.entity.titleAsync); } else { type = key.imageFileType; } typed_data.Uint8List? data; if (isOriginal) { if (key.entity.type == AssetType.video) { data = await key.entity.thumbnailData; } else if (type == ImageFileType.heic) { data = await (await key.entity.file)?.readAsBytes(); } else { data = await key.entity.originBytes; } } else { data = await key.entity.thumbnailDataWithOption( _thumbOption(thumbnailSize!), ); } if (data == null) { throw StateError('The data of the entity is null: $entity'); } final buffer = await ui.ImmutableBuffer.fromUint8List(data); return decode(buffer); } catch (e, s) { if (kDebugMode) { FlutterError.presentError( FlutterErrorDetails( exception: e, stack: s, library: PMConstants.libraryName, ), ); } // Depending on where the exception was thrown, the image cache may not // have had a chance to track the key in the cache at all. // Schedule a microtask to give the cache a chance to add the key. Future.microtask(() => _evictCache(key)); rethrow; } }).then((codec) { lock.complete(codec); }).catchError((e, s) { lock.completeError(e, s); }).whenComplete(() { _providerLocks.remove(key); }); return lock.future; } ThumbnailOption _thumbOption(ThumbnailSize size) { if (Platform.isIOS || Platform.isMacOS) { return ThumbnailOption.ios(size: size, format: thumbnailFormat); } return ThumbnailOption(size: size, format: thumbnailFormat); } /// Get image type by reading the file extension. /// 从图片后缀判断图片类型 /// /// ⚠ Not all the system version support read file name from the entity, /// so this method might not work sometime. /// 并非所有的系统版本都支持读取文件名,所以该方法有时无法返回正确的类型。 ImageFileType _getType([String? filename]) { ImageFileType? type; final String? extension = filename?.split('.').last ?? entity.mimeType?.split('/').last ?? entity.title?.split('.').last; if (extension != null) { switch (extension.toLowerCase()) { case 'jpg': case 'jpeg': type = ImageFileType.jpg; break; case 'png': type = ImageFileType.png; break; case 'gif': type = ImageFileType.gif; break; case 'tiff': type = ImageFileType.tiff; break; case 'heic': type = ImageFileType.heic; break; default: type = ImageFileType.other; break; } } return type ?? ImageFileType.other; } static void _evictCache(AssetEntityImageProvider key) { // ignore: unnecessary_cast ((PaintingBinding.instance as PaintingBinding).imageCache as ImageCache) .evict(key); } @override bool operator ==(Object other) { if (other is! AssetEntityImageProvider) { return false; } if (identical(this, other)) { return true; } return entity == other.entity && thumbnailSize == other.thumbnailSize && thumbnailFormat == other.thumbnailFormat && isOriginal == other.isOriginal; } @override int get hashCode => entity.hashCode ^ isOriginal.hashCode ^ thumbnailSize.hashCode ^ thumbnailFormat.hashCode; } /// A widget that displays an [AssetEntity] image. /// /// The widget uses [AssetEntityImageProvider] internally to resolve assets. class AssetEntityImage extends Image { AssetEntityImage( this.entity, { this.isOriginal = true, this.thumbnailSize = PMConstants.vDefaultGridThumbnailSize, this.thumbnailFormat = ThumbnailFormat.jpeg, Key? key, ImageFrameBuilder? frameBuilder, ImageLoadingBuilder? loadingBuilder, ImageErrorWidgetBuilder? errorBuilder, String? semanticLabel, bool excludeFromSemantics = false, double? width, double? height, Color? color, Animation? opacity, BlendMode? colorBlendMode, BoxFit? fit, AlignmentGeometry alignment = Alignment.center, ImageRepeat repeat = ImageRepeat.noRepeat, Rect? centerSlice, bool matchTextDirection = false, bool gaplessPlayback = false, bool isAntiAlias = false, FilterQuality filterQuality = FilterQuality.low, }) : super( key: key, image: AssetEntityImageProvider( entity, isOriginal: isOriginal, thumbnailSize: thumbnailSize, thumbnailFormat: thumbnailFormat, ), frameBuilder: frameBuilder, loadingBuilder: loadingBuilder, errorBuilder: errorBuilder, semanticLabel: semanticLabel, excludeFromSemantics: excludeFromSemantics, width: width, height: height, color: color, opacity: opacity, colorBlendMode: colorBlendMode, fit: fit, alignment: alignment, repeat: repeat, centerSlice: centerSlice, matchTextDirection: matchTextDirection, gaplessPlayback: gaplessPlayback, isAntiAlias: isAntiAlias, filterQuality: filterQuality, ); final AssetEntity entity; final bool isOriginal; final ThumbnailSize? thumbnailSize; final ThumbnailFormat thumbnailFormat; @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties.add(DiagnosticsProperty('entity', entity)); properties.add(DiagnosticsProperty('isOriginal', isOriginal)); properties.add( DiagnosticsProperty('thumbnailSize', thumbnailSize), ); properties.add( DiagnosticsProperty('thumbnailFormat', thumbnailFormat), ); } } ```
AlexV525 commented 9 months ago

The v3.0.0 of the plugin has been released. Please follow the breaking change doc to migrate usages.