Skip to content

Commit

Permalink
⚡️ Adapt Flutter 3.3 (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Aug 30, 2022
1 parent d5d4c79 commit a684b80
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions example/lib/page/save_image_example.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -22,7 +22,7 @@ class _SaveMediaExampleState extends State<SaveMediaExample> {
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";
Expand Down Expand Up @@ -130,13 +130,13 @@ class _SaveMediaExampleState extends State<SaveMediaExample> {
resp.listen((List<int> data) {
bytes.addAll(data);
}, onDone: () {
final Uint8List image = Uint8List.fromList(bytes);
final image = typed_data.Uint8List.fromList(bytes);
saveImage(image);
client.close();
});
}

Future<void> saveImage(Uint8List uint8List) async {
Future<void> saveImage(typed_data.Uint8List uint8List) async {
final AssetEntity? asset = await PhotoManager.editor.saveImage(
uint8List,
title: '${DateTime.now().millisecondsSinceEpoch}.jpg',
Expand Down
17 changes: 12 additions & 5 deletions lib/src/filter/filter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -179,7 +186,7 @@ class DurationConstraint {
}

@override
int get hashCode => hashValues(min, max, allowNullable);
int get hashCode => min.hashCode ^ max.hashCode ^ allowNullable.hashCode;
}

@immutable
Expand Down Expand Up @@ -229,7 +236,7 @@ class DateTimeCond {
}

@override
int get hashCode => hashValues(min, max, ignore);
int get hashCode => min.hashCode ^ max.hashCode ^ ignore.hashCode;
}

@immutable
Expand Down Expand Up @@ -259,5 +266,5 @@ class OrderOption {
}

@override
int get hashCode => hashValues(type, asc);
int get hashCode => type.hashCode ^ asc.hashCode;
}
19 changes: 9 additions & 10 deletions lib/src/internal/image_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -58,7 +58,7 @@ class AssetEntityImageProvider extends ImageProvider<AssetEntityImageProvider> {
@override
ImageStreamCompleter load(
AssetEntityImageProvider key,
DecoderCallback decode,
DecoderCallback decode, // ignore: deprecated_member_use
) {
return MultiFrameImageStreamCompleter(
codec: _loadAsync(key, decode),
Expand All @@ -83,7 +83,7 @@ class AssetEntityImageProvider extends ImageProvider<AssetEntityImageProvider> {

Future<ui.Codec> _loadAsync(
AssetEntityImageProvider key,
DecoderCallback decode,
DecoderCallback decode, // ignore: deprecated_member_use
) async {
try {
assert(key == this);
Expand All @@ -103,7 +103,7 @@ class AssetEntityImageProvider extends ImageProvider<AssetEntityImageProvider> {
type = key.imageFileType;
}

Uint8List? data;
typed_data.Uint8List? data;
if (isOriginal) {
if (key.entity.type == AssetType.video) {
data = await key.entity.thumbnailData;
Expand Down Expand Up @@ -204,12 +204,11 @@ class AssetEntityImageProvider extends ImageProvider<AssetEntityImageProvider> {
}

@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.
Expand Down
8 changes: 4 additions & 4 deletions lib/src/internal/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -149,7 +149,7 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin {
}

/// Get thumbnail of asset id.
Future<Uint8List?> getThumbnail({
Future<typed_data.Uint8List?> getThumbnail({
required String id,
required ThumbnailOption option,
PMProgressHandler? progressHandler,
Expand All @@ -162,7 +162,7 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin {
return _channel.invokeMethod(PMConstants.mGetThumb, params);
}

Future<Uint8List?> getOriginBytes(
Future<typed_data.Uint8List?> getOriginBytes(
String id, {
PMProgressHandler? progressHandler,
}) {
Expand Down Expand Up @@ -251,7 +251,7 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin {
}

Future<AssetEntity?> saveImage(
Uint8List data, {
typed_data.Uint8List data, {
required String? title,
String? desc,
String? relativePath,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/internal/progress_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand Down
18 changes: 8 additions & 10 deletions lib/src/managers/notify_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/foundation.dart' as foundation;
import 'package:flutter/services.dart';

import '../internal/constants.dart';
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<bool> get notifyStream => _controller.stream;
final StreamController<bool> _controller = StreamController<bool>.broadcast();
final _controller = StreamController<bool>.broadcast();

final List<ValueChanged<MethodCall>> _notifyCallback =
<ValueChanged<MethodCall>>[];
final _notifyCallback = <foundation.ValueChanged<MethodCall>>[];

/// {@template photo_manager.NotifyManager.addChangeCallback}
/// Add a callback for assets changing.
/// {@endtemplate}
void addChangeCallback(ValueChanged<MethodCall> c) => _notifyCallback.add(c);
void addChangeCallback(foundation.ValueChanged<MethodCall> c) =>
_notifyCallback.add(c);

/// {@template photo_manager.NotifyManager.removeChangeCallback}
/// Remove the callback for assets changing.
/// {@endtemplate}
void removeChangeCallback(ValueChanged<MethodCall> c) =>
void removeChangeCallback(foundation.ValueChanged<MethodCall> c) =>
_notifyCallback.remove(c);

/// {@template photo_manager.NotifyManager.startChangeNotify}
Expand Down Expand Up @@ -71,7 +69,7 @@ class NotifyManager {
}

Future<dynamic> _onChange(MethodCall m) async {
_notifyCallback.toList().forEach((ValueChanged<MethodCall> c) => c.call(m));
_notifyCallback.toList().forEach((c) => c.call(m));
}

@override
Expand Down
31 changes: 18 additions & 13 deletions lib/src/types/entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<Uint8List?> get originBytes => _getOriginBytes();
Future<typed_data.Uint8List?> get originBytes => _getOriginBytes();

/// Obtain the thumbnail data with [PMConstants.vDefaultThumbnailSize]
/// size of the asset, typically use it for preview displays.
Expand All @@ -527,7 +532,7 @@ class AssetEntity {
/// See also:
/// * [thumbnailDataWithSize] which is a common method to obtain thumbnails.
/// * [thumbnailDataWithOption] which accepts customized [ThumbnailOption].
Future<Uint8List?> get thumbnailData => thumbnailDataWithSize(
Future<typed_data.Uint8List?> get thumbnailData => thumbnailDataWithSize(
const ThumbnailSize.square(PMConstants.vDefaultThumbnailSize),
);

Expand All @@ -538,7 +543,7 @@ class AssetEntity {
/// See also:
/// * [thumbnailData] which obtain the thumbnail data with fixed size.
/// * [thumbnailDataWithOption] which accepts customized [ThumbnailOption].
Future<Uint8List?> thumbnailDataWithSize(
Future<typed_data.Uint8List?> thumbnailDataWithSize(
ThumbnailSize size, {
ThumbnailFormat format = ThumbnailFormat.jpeg,
int quality = 100,
Expand All @@ -550,7 +555,7 @@ class AssetEntity {
}());
// Return null if the asset is audio or others.
if (type == AssetType.audio || type == AssetType.other) {
return Future<Uint8List?>.value();
return Future<typed_data.Uint8List?>.value();
}
final ThumbnailOption option;
if (Platform.isIOS || Platform.isMacOS) {
Expand Down Expand Up @@ -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<Uint8List?> thumbnailDataWithOption(
Future<typed_data.Uint8List?> thumbnailDataWithOption(
ThumbnailOption option, {
PMProgressHandler? progressHandler,
}) {
Expand All @@ -589,7 +594,7 @@ class AssetEntity {
}());
// Return null if the asset is audio or others.
if (type == AssetType.audio || type == AssetType.other) {
return Future<Uint8List?>.value();
return Future<typed_data.Uint8List?>.value();
}
assert(() {
option.checkAssertions();
Expand Down Expand Up @@ -684,7 +689,7 @@ class AssetEntity {
return File(path);
}

Future<Uint8List?> _getOriginBytes({
Future<typed_data.Uint8List?> _getOriginBytes({
PMProgressHandler? progressHandler,
}) async {
assert(
Expand Down Expand Up @@ -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) {
Expand All @@ -805,14 +810,14 @@ class LatLng {
final double? latitude;
final double? longitude;

@override
int get hashCode => hashValues(latitude, longitude);

@override
bool operator ==(Object other) {
if (other is! AssetEntity) {
return false;
}
return latitude == other.latitude && longitude == other.longitude;
}

@override
int get hashCode => latitude.hashCode ^ longitude.hashCode;
}
11 changes: 7 additions & 4 deletions lib/src/types/thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a684b80

Please sign in to comment.