diff --git a/CHANGELOG.md b/CHANGELOG.md index fe792530..82ef4278 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ that can be found in the LICENSE file. --> ### Improvements +- Adapt Flutter 3.3. (#820) - Retrieve metadata for videos when empty on Android. (#819) ## 2.3.0-dev.1 diff --git a/example/lib/page/save_image_example.dart b/example/lib/page/save_image_example.dart index 8c398245..72c06d17 100644 --- a/example/lib/page/save_image_example.dart +++ b/example/lib/page/save_image_example.dart @@ -1,5 +1,5 @@ import 'dart:io'; -import 'dart:typed_data'; +import 'dart:typed_data' as typed_data; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -22,7 +22,7 @@ class _SaveMediaExampleState extends State { final String haveExifUrl = 'http://172.16.100.7:2393/IMG_20200107_182905.jpg'; final String videoUrl = - 'http://img.ksbbs.com/asset/Mon_1703/05cacb4e02f9d9e.mp4'; + 'https://pic.app.kszhuangxiu.com/forum/20220423120218front2_1_788292_FhP_XBo24M5XuZzb4xPb-YPaC6Yq.mp4'; // final videoUrl = "http://192.168.31.252:51781/out.mov"; // final videoUrl = "http://192.168.31.252:51781/out.ogv"; @@ -130,13 +130,13 @@ class _SaveMediaExampleState extends State { resp.listen((List data) { bytes.addAll(data); }, onDone: () { - final Uint8List image = Uint8List.fromList(bytes); + final image = typed_data.Uint8List.fromList(bytes); saveImage(image); client.close(); }); } - Future saveImage(Uint8List uint8List) async { + Future saveImage(typed_data.Uint8List uint8List) async { final AssetEntity? asset = await PhotoManager.editor.saveImage( uint8List, title: '${DateTime.now().millisecondsSinceEpoch}.jpg', diff --git a/lib/src/filter/filter_options.dart b/lib/src/filter/filter_options.dart index 9d98c66d..5004c38b 100644 --- a/lib/src/filter/filter_options.dart +++ b/lib/src/filter/filter_options.dart @@ -72,7 +72,10 @@ class FilterOption { } @override - int get hashCode => hashValues(needTitle, sizeConstraint, durationConstraint); + int get hashCode => + needTitle.hashCode ^ + sizeConstraint.hashCode ^ + durationConstraint.hashCode; } /// Constraints of asset pixel width and height. @@ -139,7 +142,11 @@ class SizeConstraint { @override int get hashCode => - hashValues(minWidth, maxWidth, minHeight, maxHeight, ignoreSize); + minWidth.hashCode ^ + maxWidth.hashCode ^ + minHeight.hashCode ^ + maxHeight.hashCode ^ + ignoreSize.hashCode; } /// Constraints of duration. @@ -179,7 +186,7 @@ class DurationConstraint { } @override - int get hashCode => hashValues(min, max, allowNullable); + int get hashCode => min.hashCode ^ max.hashCode ^ allowNullable.hashCode; } @immutable @@ -229,7 +236,7 @@ class DateTimeCond { } @override - int get hashCode => hashValues(min, max, ignore); + int get hashCode => min.hashCode ^ max.hashCode ^ ignore.hashCode; } @immutable @@ -259,5 +266,5 @@ class OrderOption { } @override - int get hashCode => hashValues(type, asc); + int get hashCode => type.hashCode ^ asc.hashCode; } diff --git a/lib/src/internal/image_provider.dart b/lib/src/internal/image_provider.dart index 91f46583..e82e6a28 100644 --- a/lib/src/internal/image_provider.dart +++ b/lib/src/internal/image_provider.dart @@ -3,7 +3,7 @@ // in the LICENSE file. import 'dart:io'; -import 'dart:typed_data'; +import 'dart:typed_data' as typed_data; import 'dart:ui' as ui; import 'package:flutter/foundation.dart'; @@ -58,7 +58,7 @@ class AssetEntityImageProvider extends ImageProvider { @override ImageStreamCompleter load( AssetEntityImageProvider key, - DecoderCallback decode, + DecoderCallback decode, // ignore: deprecated_member_use ) { return MultiFrameImageStreamCompleter( codec: _loadAsync(key, decode), @@ -83,7 +83,7 @@ class AssetEntityImageProvider extends ImageProvider { Future _loadAsync( AssetEntityImageProvider key, - DecoderCallback decode, + DecoderCallback decode, // ignore: deprecated_member_use ) async { try { assert(key == this); @@ -103,7 +103,7 @@ class AssetEntityImageProvider extends ImageProvider { type = key.imageFileType; } - Uint8List? data; + typed_data.Uint8List? data; if (isOriginal) { if (key.entity.type == AssetType.video) { data = await key.entity.thumbnailData; @@ -204,12 +204,11 @@ class AssetEntityImageProvider extends ImageProvider { } @override - int get hashCode => hashValues( - entity, - isOriginal, - thumbnailSize, - thumbnailFormat, - ); + int get hashCode => + entity.hashCode ^ + isOriginal.hashCode ^ + thumbnailSize.hashCode ^ + thumbnailFormat.hashCode; } /// A widget that displays an [AssetEntity] image. diff --git a/lib/src/internal/plugin.dart b/lib/src/internal/plugin.dart index 654c1369..6e2ad9f4 100644 --- a/lib/src/internal/plugin.dart +++ b/lib/src/internal/plugin.dart @@ -4,7 +4,7 @@ import 'dart:async'; import 'dart:io'; -import 'dart:typed_data'; +import 'dart:typed_data' as typed_data; import 'package:flutter/services.dart'; @@ -149,7 +149,7 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin { } /// Get thumbnail of asset id. - Future getThumbnail({ + Future getThumbnail({ required String id, required ThumbnailOption option, PMProgressHandler? progressHandler, @@ -162,7 +162,7 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin { return _channel.invokeMethod(PMConstants.mGetThumb, params); } - Future getOriginBytes( + Future getOriginBytes( String id, { PMProgressHandler? progressHandler, }) { @@ -251,7 +251,7 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin { } Future saveImage( - Uint8List data, { + typed_data.Uint8List data, { required String? title, String? desc, String? relativePath, diff --git a/lib/src/internal/progress_handler.dart b/lib/src/internal/progress_handler.dart index d34cab9f..d652622d 100644 --- a/lib/src/internal/progress_handler.dart +++ b/lib/src/internal/progress_handler.dart @@ -76,7 +76,7 @@ class PMProgressState { } @override - int get hashCode => hashValues(progress, state); + int get hashCode => progress.hashCode ^ state.hashCode; @override String toString() => '$runtimeType($state, $progress)'; diff --git a/lib/src/managers/notify_manager.dart b/lib/src/managers/notify_manager.dart index 6c624740..086e612e 100644 --- a/lib/src/managers/notify_manager.dart +++ b/lib/src/managers/notify_manager.dart @@ -4,7 +4,7 @@ import 'dart:async'; -import 'package:flutter/foundation.dart'; +import 'package:flutter/foundation.dart' as foundation; import 'package:flutter/services.dart'; import '../internal/constants.dart'; @@ -12,25 +12,23 @@ import '../internal/plugin.dart'; /// The notify manager when assets changed. class NotifyManager { - static const MethodChannel _channel = MethodChannel( - '${PMConstants.channelPrefix}/notify', - ); + static const _channel = MethodChannel('${PMConstants.channelPrefix}/notify'); Stream get notifyStream => _controller.stream; - final StreamController _controller = StreamController.broadcast(); + final _controller = StreamController.broadcast(); - final List> _notifyCallback = - >[]; + final _notifyCallback = >[]; /// {@template photo_manager.NotifyManager.addChangeCallback} /// Add a callback for assets changing. /// {@endtemplate} - void addChangeCallback(ValueChanged c) => _notifyCallback.add(c); + void addChangeCallback(foundation.ValueChanged c) => + _notifyCallback.add(c); /// {@template photo_manager.NotifyManager.removeChangeCallback} /// Remove the callback for assets changing. /// {@endtemplate} - void removeChangeCallback(ValueChanged c) => + void removeChangeCallback(foundation.ValueChanged c) => _notifyCallback.remove(c); /// {@template photo_manager.NotifyManager.startChangeNotify} @@ -71,7 +69,7 @@ class NotifyManager { } Future _onChange(MethodCall m) async { - _notifyCallback.toList().forEach((ValueChanged c) => c.call(m)); + _notifyCallback.toList().forEach((c) => c.call(m)); } @override diff --git a/lib/src/types/entity.dart b/lib/src/types/entity.dart index 69832523..6adaf837 100644 --- a/lib/src/types/entity.dart +++ b/lib/src/types/entity.dart @@ -3,7 +3,7 @@ // in the LICENSE file. import 'dart:io'; -import 'dart:typed_data'; +import 'dart:typed_data' as typed_data; import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; @@ -280,7 +280,12 @@ class AssetPathEntity { @override int get hashCode => - hashValues(id, name, albumType, type, lastModified, isAll); + id.hashCode ^ + name.hashCode ^ + albumType.hashCode ^ + type.hashCode ^ + lastModified.hashCode ^ + isAll.hashCode; @override String toString() { @@ -515,7 +520,7 @@ class AssetEntity { /// /// **Use it with cautious** since the original data might be epic large. /// Generally use this method only for images. - Future get originBytes => _getOriginBytes(); + Future get originBytes => _getOriginBytes(); /// Obtain the thumbnail data with [PMConstants.vDefaultThumbnailSize] /// size of the asset, typically use it for preview displays. @@ -527,7 +532,7 @@ class AssetEntity { /// See also: /// * [thumbnailDataWithSize] which is a common method to obtain thumbnails. /// * [thumbnailDataWithOption] which accepts customized [ThumbnailOption]. - Future get thumbnailData => thumbnailDataWithSize( + Future get thumbnailData => thumbnailDataWithSize( const ThumbnailSize.square(PMConstants.vDefaultThumbnailSize), ); @@ -538,7 +543,7 @@ class AssetEntity { /// See also: /// * [thumbnailData] which obtain the thumbnail data with fixed size. /// * [thumbnailDataWithOption] which accepts customized [ThumbnailOption]. - Future thumbnailDataWithSize( + Future thumbnailDataWithSize( ThumbnailSize size, { ThumbnailFormat format = ThumbnailFormat.jpeg, int quality = 100, @@ -550,7 +555,7 @@ class AssetEntity { }()); // Return null if the asset is audio or others. if (type == AssetType.audio || type == AssetType.other) { - return Future.value(); + return Future.value(); } final ThumbnailOption option; if (Platform.isIOS || Platform.isMacOS) { @@ -579,7 +584,7 @@ class AssetEntity { /// See also: /// * [thumbnailData] which obtain the thumbnail data with fixed size. /// * [thumbnailDataWithSize] which is a common method to obtain thumbnails. - Future thumbnailDataWithOption( + Future thumbnailDataWithOption( ThumbnailOption option, { PMProgressHandler? progressHandler, }) { @@ -589,7 +594,7 @@ class AssetEntity { }()); // Return null if the asset is audio or others. if (type == AssetType.audio || type == AssetType.other) { - return Future.value(); + return Future.value(); } assert(() { option.checkAssertions(); @@ -684,7 +689,7 @@ class AssetEntity { return File(path); } - Future _getOriginBytes({ + Future _getOriginBytes({ PMProgressHandler? progressHandler, }) async { assert( @@ -783,7 +788,7 @@ class AssetEntity { } @override - int get hashCode => hashValues(id, isFavorite); + int get hashCode => id.hashCode ^ isFavorite.hashCode; @override bool operator ==(Object other) { @@ -805,9 +810,6 @@ class LatLng { final double? latitude; final double? longitude; - @override - int get hashCode => hashValues(latitude, longitude); - @override bool operator ==(Object other) { if (other is! AssetEntity) { @@ -815,4 +817,7 @@ class LatLng { } return latitude == other.latitude && longitude == other.longitude; } + + @override + int get hashCode => latitude.hashCode ^ longitude.hashCode; } diff --git a/lib/src/types/thumbnail.dart b/lib/src/types/thumbnail.dart index 9f1b1ab1..43f13b9c 100644 --- a/lib/src/types/thumbnail.dart +++ b/lib/src/types/thumbnail.dart @@ -3,7 +3,6 @@ // in the LICENSE file. import 'package:flutter/foundation.dart'; -import 'package:flutter/rendering.dart'; import '../internal/constants.dart'; import '../internal/enums.dart'; @@ -43,7 +42,7 @@ class ThumbnailSize { } @override - int get hashCode => hashValues(width, height); + int get hashCode => width.hashCode ^ height.hashCode; @override String toString() => 'ThumbnailSize($width, $height)'; @@ -117,7 +116,8 @@ class ThumbnailOption { } @override - int get hashCode => hashValues(size, format, quality, frame); + int get hashCode => + size.hashCode ^ format.hashCode ^ quality.hashCode ^ frame.hashCode; @override bool operator ==(Object other) { @@ -158,7 +158,10 @@ class _IOSThumbnailOption extends ThumbnailOption { @override int get hashCode => - hashValues(super.hashCode, deliveryMode, resizeMode, resizeContentMode); + super.hashCode ^ + deliveryMode.hashCode ^ + resizeMode.hashCode ^ + resizeContentMode.hashCode; @override bool operator ==(Object other) {