Skip to content

Commit

Permalink
[flutter] Upgraded to Flutter 3.16.0, fixes #2420
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Nov 26, 2023
1 parent 14089db commit 5888719
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 33 deletions.
2 changes: 1 addition & 1 deletion spine-flutter/example/lib/dress_up.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 21 additions & 21 deletions spine-flutter/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -169,7 +169,7 @@ packages:
path: ".."
relative: true
source: path
version: "4.1.4"
version: "4.1.7"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -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:
Expand All @@ -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"
8 changes: 4 additions & 4 deletions spine-flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ 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:
sdk: flutter

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
Expand Down
120 changes: 120 additions & 0 deletions spine-flutter/lib/raw_image_provider.dart
Original file line number Diff line number Diff line change
@@ -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<ui.Codec> _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));
}
}
3 changes: 2 additions & 1 deletion spine-flutter/lib/spine_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
12 changes: 6 additions & 6 deletions spine-flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5888719

Please sign in to comment.