From 58887199cab41e561e52f098d840e75744075e1a Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sun, 26 Nov 2023 13:59:38 +0100 Subject: [PATCH] [flutter] Upgraded to Flutter 3.16.0, fixes #2420 --- spine-flutter/example/lib/dress_up.dart | 2 +- spine-flutter/example/pubspec.lock | 42 ++++---- spine-flutter/example/pubspec.yaml | 8 +- spine-flutter/lib/raw_image_provider.dart | 120 ++++++++++++++++++++++ spine-flutter/lib/spine_flutter.dart | 3 +- spine-flutter/pubspec.yaml | 12 +-- 6 files changed, 154 insertions(+), 33 deletions(-) create mode 100644 spine-flutter/lib/raw_image_provider.dart diff --git a/spine-flutter/example/lib/dress_up.dart b/spine-flutter/example/lib/dress_up.dart index 9271b57137..5105dfca11 100644 --- a/spine-flutter/example/lib/dress_up.dart +++ b/spine-flutter/example/lib/dress_up.dart @@ -27,10 +27,10 @@ /// SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /// +import 'package:spine_flutter/raw_image_provider.dart'; import 'package:spine_flutter/spine_flutter.dart'; import 'package:flutter/material.dart'; import 'package:flutter/painting.dart' as painting; -import 'package:raw_image_provider/raw_image_provider.dart'; class DressUp extends StatefulWidget { const DressUp({Key? key}) : super(key: key); diff --git a/spine-flutter/example/pubspec.lock b/spine-flutter/example/pubspec.lock index d1522f5048..ed2be16d83 100644 --- a/spine-flutter/example/pubspec.lock +++ b/spine-flutter/example/pubspec.lock @@ -21,10 +21,10 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" crypto: dependency: transitive description: @@ -37,26 +37,26 @@ packages: dependency: "direct main" description: name: cupertino_icons - sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be + sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d url: "https://pub.dev" source: hosted - version: "1.0.5" + version: "1.0.6" ffi: dependency: transitive description: name: ffi - sha256: ed5337a5660c506388a9f012be0288fb38b49020ce2b45fe1f8b8323fe429f99 + sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878" url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "2.1.0" flame: dependency: "direct main" description: name: flame - sha256: "12db9de3cd31b86465b0c1ea173020fb71b15df424ca01b665fa5300b24864c8" + sha256: b6bb76224fc29fd5eea25d66cda6e322e3678bdedc1f65956c6151326a6a798b url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.10.1" flutter: dependency: "direct main" description: flutter @@ -66,10 +66,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: "2118df84ef0c3ca93f96123a616ae8540879991b8b57af2f81b76a7ada49b2a4" + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 url: "https://pub.dev" source: hosted - version: "2.0.2" + version: "3.0.1" http: dependency: transitive description: @@ -106,10 +106,10 @@ packages: dependency: transitive description: name: lints - sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "3.0.0" material_color_utilities: dependency: transitive description: @@ -122,18 +122,18 @@ packages: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" ordered_set: dependency: transitive description: name: ordered_set - sha256: "3fedcc9121b3ba24c0a84f32da2989c42e36c159b73feadbc2f402dc55966b81" + sha256: "3858c7d84619edfab87c3e367584648020903187edb70b52697646f4b2a93022" url: "https://pub.dev" source: hosted - version: "5.0.1" + version: "5.0.2" path: dependency: transitive description: @@ -169,7 +169,7 @@ packages: path: ".." relative: true source: path - version: "4.1.4" + version: "4.1.7" string_scanner: dependency: transitive description: @@ -206,10 +206,10 @@ packages: dependency: transitive description: name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "0.3.0" web_ffi_fork: dependency: transitive description: @@ -219,5 +219,5 @@ packages: source: hosted version: "0.7.4" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" - flutter: ">=3.10.5" + dart: ">=3.2.0-194.0.dev <4.0.0" + flutter: ">=3.16.0" diff --git a/spine-flutter/example/pubspec.yaml b/spine-flutter/example/pubspec.yaml index a6911a4a0d..6a1071f17b 100644 --- a/spine-flutter/example/pubspec.yaml +++ b/spine-flutter/example/pubspec.yaml @@ -5,7 +5,7 @@ version: 1.0.0+1 environment: sdk: '>=2.17.6 <4.0.0' - flutter: ">=3.10.5" + flutter: ">=3.16.0 <4.0.0" dependencies: flutter: @@ -13,12 +13,12 @@ dependencies: spine_flutter: path: ../ - cupertino_icons: ^1.0.2 - flame: ^1.4.0 + cupertino_icons: ^1.0.6 + flame: ^1.10.1 raw_image_provider: ^0.2.0 dev_dependencies: - flutter_lints: ^2.0.0 + flutter_lints: ^3.0.1 flutter: uses-material-design: true diff --git a/spine-flutter/lib/raw_image_provider.dart b/spine-flutter/lib/raw_image_provider.dart new file mode 100644 index 0000000000..1ed7422b64 --- /dev/null +++ b/spine-flutter/lib/raw_image_provider.dart @@ -0,0 +1,120 @@ +// MIT License +// +// Copyright (c) 2021 Yrom Wang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +import 'dart:typed_data'; +import 'dart:ui' as ui; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; +import 'package:crypto/crypto.dart'; + +/// Decodes the given [image] (raw image pixel data) as an image ('dart:ui') +class RawImageProvider extends ImageProvider<_RawImageKey> { + final RawImageData image; + final double? scale; + final int? targetWidth; + final int? targetHeight; + RawImageProvider( + this.image, { + this.scale = 1.0, + this.targetWidth, + this.targetHeight, + }); + + @override + ImageStreamCompleter loadImage(_RawImageKey key, ImageDecoderCallback decode) { + return MultiFrameImageStreamCompleter( + codec: _loadAsync(key), + scale: scale ?? 1.0, + debugLabel: 'RawImageProvider(${describeIdentity(key)})', + ); + } + + @override + Future<_RawImageKey> obtainKey(ImageConfiguration configuration) { + return SynchronousFuture(image._obtainKey()); + } + + /// see [ui.decodeImageFromPixels] + Future _loadAsync(_RawImageKey key) async { + assert(key == image._obtainKey()); + // rgba8888 pixels + var buffer = await ui.ImmutableBuffer.fromUint8List(image.pixels); + + final descriptor = ui.ImageDescriptor.raw( + buffer, + width: image.width, + height: image.height, + pixelFormat: image.pixelFormat, + ); + assert(() { + debugPrint('ImageDescriptor: ${descriptor.width}x${descriptor.height}'); + return true; + }()); + return descriptor.instantiateCodec( + targetWidth: targetWidth, targetHeight: targetHeight); + } +} + +class _RawImageKey { + final int w; + final int h; + final int format; + final Digest dataHash; + _RawImageKey(this.w, this.h, this.format, this.dataHash); + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is _RawImageKey && + other.w == w && + other.h == h && + other.format == format && + other.dataHash == dataHash; + } + + @override + int get hashCode { + return hashValues(w, h, format, dataHash.hashCode); + } +} + +/// Raw pixels data of an image +class RawImageData { + final Uint8List pixels; + final int width; + final int height; + final ui.PixelFormat pixelFormat; + + RawImageData( + this.pixels, + this.width, + this.height, { + this.pixelFormat = ui.PixelFormat.rgba8888, + }); + + _RawImageKey? _key; + _RawImageKey _obtainKey() { + return _key ??= + _RawImageKey(width, height, pixelFormat.index, md5.convert(pixels)); + } +} diff --git a/spine-flutter/lib/spine_flutter.dart b/spine-flutter/lib/spine_flutter.dart index 8fdc66c3f2..6995757229 100644 --- a/spine-flutter/lib/spine_flutter.dart +++ b/spine-flutter/lib/spine_flutter.dart @@ -38,11 +38,12 @@ import 'package:flutter/rendering.dart' as rendering; import 'package:flutter/services.dart'; import 'package:http/http.dart' as http; import 'package:path/path.dart' as path; -import 'package:raw_image_provider/raw_image_provider.dart'; + import 'ffi_proxy.dart'; import 'init.dart' if (dart.library.html) 'init_web.dart'; import 'spine_flutter_bindings_generated.dart'; +import 'raw_image_provider.dart'; export 'spine_widget.dart'; diff --git a/spine-flutter/pubspec.yaml b/spine-flutter/pubspec.yaml index 6b5d7b6595..217f4f979e 100644 --- a/spine-flutter/pubspec.yaml +++ b/spine-flutter/pubspec.yaml @@ -8,23 +8,23 @@ documentation: https://esotericsoftware.com/spine-flutter environment: sdk: '>=2.17.6 <4.0.0' - flutter: ">=3.10.5" + flutter: ">=3.16.0 <4.0.0" dependencies: flutter: sdk: flutter - ffi: ^2.0.1 + ffi: ^2.1.0 web_ffi_fork: ^0.7.4 inject_js: ^2.0.0 js: ^0.6.5 - meta: ^1.8.0 + meta: ^1.10.0 http: ^1.1.0 path: ^1.8.2 - raw_image_provider: ^0.2.0 + crypto: ^3.0.3 dev_dependencies: - ffigen: ^9.0.1 - flutter_lints: ^2.0.0 + ffigen: ^10.0.0 + flutter_lints: ^3.0.1 flutter: plugin: