[flutter] Formatting.

This commit is contained in:
Mario Zechner 2022-12-06 10:06:28 +01:00
parent 1cf95f49d2
commit ef3403d8ba
5 changed files with 1718 additions and 3401 deletions

View File

@ -1,2 +1,3 @@
export 'dart:ffi' if (dart.library.html) 'package:web_ffi_fork/web_ffi.dart'; export 'dart:ffi' if (dart.library.html) 'package:web_ffi_fork/web_ffi.dart';
export 'package:ffi/ffi.dart' if (dart.library.html) 'package:web_ffi_fork/src/ffi/utf8.dart'; export 'package:ffi/ffi.dart' if (dart.library.html) 'package:web_ffi_fork/src/ffi/utf8.dart';

View File

@ -1,5 +1,6 @@
import 'dart:io';
import 'dart:ffi'; import 'dart:ffi';
import 'dart:io';
import 'package:ffi/ffi.dart'; import 'package:ffi/ffi.dart';
const String _libName = 'esotericsoftware_spine_flutter'; const String _libName = 'esotericsoftware_spine_flutter';

View File

@ -4,6 +4,7 @@ import 'dart:math';
import 'dart:typed_data'; import 'dart:typed_data';
import 'dart:ui'; import 'dart:ui';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart' as material; import 'package:flutter/material.dart' as material;
import 'package:flutter/rendering.dart' as rendering; import 'package:flutter/rendering.dart' as rendering;
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -11,12 +12,11 @@ import 'package:http/http.dart' as http;
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:raw_image_provider/raw_image_provider.dart'; import 'package:raw_image_provider/raw_image_provider.dart';
import 'spine_flutter_bindings_generated.dart';
import 'ffi_proxy.dart'; import 'ffi_proxy.dart';
import 'init.dart' if (dart.library.html) 'init_web.dart';
import 'spine_flutter_bindings_generated.dart';
export 'spine_widget.dart'; export 'spine_widget.dart';
import 'init.dart' if (dart.library.html) 'init_web.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
late SpineFlutterBindings _bindings; late SpineFlutterBindings _bindings;
late Allocator _allocator; late Allocator _allocator;
@ -94,8 +94,7 @@ class Atlas {
final Image image = frameInfo.image; final Image image = frameInfo.image;
atlasPages.add(image); atlasPages.add(image);
atlasPagePaints.add(Paint() atlasPagePaints.add(Paint()
..shader = ImageShader(image, TileMode.clamp, TileMode.clamp, Matrix4.identity().storage, ..shader = ImageShader(image, TileMode.clamp, TileMode.clamp, Matrix4.identity().storage, filterQuality: FilterQuality.high)
filterQuality: FilterQuality.high)
..isAntiAlias = true); ..isAntiAlias = true);
} }
@ -610,10 +609,7 @@ class BoneData {
Color getColor() { Color getColor() {
final color = _bindings.spine_bone_data_get_color(_data); final color = _bindings.spine_bone_data_get_color(_data);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -648,8 +644,7 @@ class Bone {
_bindings.spine_bone_update_world_transform(_bone); _bindings.spine_bone_update_world_transform(_bone);
} }
void updateWorldTransformWith( void updateWorldTransformWith(double x, double y, double rotation, double scaleX, double scaleY, double shearX, double shearY) {
double x, double y, double rotation, double scaleX, double scaleY, double shearX, double shearY) {
_bindings.spine_bone_update_world_transform_with(_bone, x, y, rotation, scaleX, scaleY, shearX, shearY); _bindings.spine_bone_update_world_transform_with(_bone, x, y, rotation, scaleX, scaleY, shearX, shearY);
} }
@ -920,10 +915,7 @@ class SlotData {
Color getColor() { Color getColor() {
final color = _bindings.spine_slot_data_get_color(_data); final color = _bindings.spine_slot_data_get_color(_data);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -933,10 +925,7 @@ class SlotData {
Color getDarkColor() { Color getDarkColor() {
final color = _bindings.spine_slot_data_get_dark_color(_data); final color = _bindings.spine_slot_data_get_dark_color(_data);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1000,10 +989,7 @@ class Slot {
Color getColor() { Color getColor() {
final color = _bindings.spine_slot_get_color(_slot); final color = _bindings.spine_slot_get_color(_slot);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1013,10 +999,7 @@ class Slot {
Color getDarkColor() { Color getDarkColor() {
final color = _bindings.spine_slot_get_dark_color(_slot); final color = _bindings.spine_slot_get_dark_color(_slot);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1339,10 +1322,7 @@ class RegionAttachment extends Attachment<spine_region_attachment> {
Color getColor() { Color getColor() {
final color = _bindings.spine_region_attachment_get_color(_attachment); final color = _bindings.spine_region_attachment_get_color(_attachment);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1451,10 +1431,7 @@ class MeshAttachment extends VertexAttachment<spine_mesh_attachment> {
Color getColor() { Color getColor() {
final color = _bindings.spine_mesh_attachment_get_color(_attachment); final color = _bindings.spine_mesh_attachment_get_color(_attachment);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1527,10 +1504,7 @@ class ClippingAttachment extends VertexAttachment<spine_clipping_attachment> {
Color getColor() { Color getColor() {
final color = _bindings.spine_clipping_attachment_get_color(_attachment); final color = _bindings.spine_clipping_attachment_get_color(_attachment);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1544,10 +1518,7 @@ class BoundingBoxAttachment extends VertexAttachment<spine_bounding_box_attachme
Color getColor() { Color getColor() {
final color = _bindings.spine_bounding_box_attachment_get_color(_attachment); final color = _bindings.spine_bounding_box_attachment_get_color(_attachment);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1583,10 +1554,7 @@ class PathAttachment extends VertexAttachment<spine_path_attachment> {
Color getColor() { Color getColor() {
final color = _bindings.spine_path_attachment_get_color(_attachment); final color = _bindings.spine_path_attachment_get_color(_attachment);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1635,10 +1603,7 @@ class PointAttachment extends Attachment<spine_point_attachment> {
Color getColor() { Color getColor() {
final color = _bindings.spine_point_attachment_get_color(_attachment); final color = _bindings.spine_point_attachment_get_color(_attachment);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -1675,8 +1640,7 @@ class Skin {
void setAttachment(int slotIndex, String name, Attachment? attachment) { void setAttachment(int slotIndex, String name, Attachment? attachment) {
final nativeName = name.toNativeUtf8(allocator: _allocator); final nativeName = name.toNativeUtf8(allocator: _allocator);
_bindings.spine_skin_set_attachment( _bindings.spine_skin_set_attachment(_skin, slotIndex, nativeName.cast(), attachment == null ? nullptr : attachment._attachment.cast());
_skin, slotIndex, nativeName.cast(), attachment == null ? nullptr : attachment._attachment.cast());
_allocator.free(nativeName); _allocator.free(nativeName);
} }
@ -1710,8 +1674,12 @@ class Skin {
for (int i = 0; i < numEntries; i++) { for (int i = 0; i < numEntries; i++) {
final entry = _bindings.spine_skin_entries_get_entry(entries, i); final entry = _bindings.spine_skin_entries_get_entry(entries, i);
Pointer<Utf8> name = _bindings.spine_skin_entry_get_name(entry).cast(); Pointer<Utf8> name = _bindings.spine_skin_entry_get_name(entry).cast();
result.add(SkinEntry(_bindings.spine_skin_entry_get_slot_index(entry), name.toDartString(), result.add(SkinEntry(
_bindings.spine_skin_entry_get_attachment(entry).address == nullptr.address ? null : Attachment._toSubclass(_bindings.spine_skin_entry_get_attachment(entry)))); _bindings.spine_skin_entry_get_slot_index(entry),
name.toDartString(),
_bindings.spine_skin_entry_get_attachment(entry).address == nullptr.address
? null
: Attachment._toSubclass(_bindings.spine_skin_entry_get_attachment(entry))));
} }
return result; return result;
} }
@ -2404,8 +2372,7 @@ class Skeleton {
Attachment? getAttachmentByName(String slotName, String attachmentName) { Attachment? getAttachmentByName(String slotName, String attachmentName) {
final slotNameNative = slotName.toNativeUtf8(allocator: _allocator); final slotNameNative = slotName.toNativeUtf8(allocator: _allocator);
final attachmentNameNative = attachmentName.toNativeUtf8(allocator: _allocator); final attachmentNameNative = attachmentName.toNativeUtf8(allocator: _allocator);
final attachment = final attachment = _bindings.spine_skeleton_get_attachment_by_name(_skeleton, slotNameNative.cast(), attachmentNameNative.cast());
_bindings.spine_skeleton_get_attachment_by_name(_skeleton, slotNameNative.cast(), attachmentNameNative.cast());
_allocator.free(slotNameNative); _allocator.free(slotNameNative);
_allocator.free(attachmentNameNative); _allocator.free(attachmentNameNative);
if (attachment.address == nullptr.address) return null; if (attachment.address == nullptr.address) return null;
@ -2460,11 +2427,8 @@ class Skeleton {
/// @param outVertexBuffer Reference to hold a Vector of floats. This method will assign it with new floats as needed. /// @param outVertexBuffer Reference to hold a Vector of floats. This method will assign it with new floats as needed.
Bounds getBounds() { Bounds getBounds() {
final nativeBounds = _bindings.spine_skeleton_get_bounds(_skeleton); final nativeBounds = _bindings.spine_skeleton_get_bounds(_skeleton);
final bounds = Bounds( final bounds = Bounds(_bindings.spine_bounds_get_x(nativeBounds), _bindings.spine_bounds_get_y(nativeBounds),
_bindings.spine_bounds_get_x(nativeBounds), _bindings.spine_bounds_get_width(nativeBounds), _bindings.spine_bounds_get_height(nativeBounds));
_bindings.spine_bounds_get_y(nativeBounds),
_bindings.spine_bounds_get_width(nativeBounds),
_bindings.spine_bounds_get_height(nativeBounds));
_allocator.free(nativeBounds); _allocator.free(nativeBounds);
return bounds; return bounds;
} }
@ -2549,10 +2513,7 @@ class Skeleton {
Color getColor() { Color getColor() {
final color = _bindings.spine_skeleton_get_color(_skeleton); final color = _bindings.spine_skeleton_get_color(_skeleton);
return Color( return Color(_bindings.spine_color_get_r(color), _bindings.spine_color_get_g(color), _bindings.spine_color_get_b(color),
_bindings.spine_color_get_r(color),
_bindings.spine_color_get_g(color),
_bindings.spine_color_get_b(color),
_bindings.spine_color_get_a(color)); _bindings.spine_color_get_a(color));
} }
@ -3154,16 +3115,14 @@ class AnimationState {
/// after AnimationState.Dispose. /// after AnimationState.Dispose.
TrackEntry setAnimationByName(int trackIndex, String animationName, bool loop) { TrackEntry setAnimationByName(int trackIndex, String animationName, bool loop) {
final animation = animationName.toNativeUtf8(allocator: _allocator); final animation = animationName.toNativeUtf8(allocator: _allocator);
final entry = final entry = _bindings.spine_animation_state_set_animation_by_name(_state, trackIndex, animation.cast(), loop ? -1 : 0);
_bindings.spine_animation_state_set_animation_by_name(_state, trackIndex, animation.cast(), loop ? -1 : 0);
_allocator.free(animation); _allocator.free(animation);
if (entry.address == nullptr.address) throw Exception("Couldn't set animation $animationName"); if (entry.address == nullptr.address) throw Exception("Couldn't set animation $animationName");
return TrackEntry._(entry, this); return TrackEntry._(entry, this);
} }
TrackEntry setAnimation(int trackIndex, Animation animation, bool loop) { TrackEntry setAnimation(int trackIndex, Animation animation, bool loop) {
final entry = final entry = _bindings.spine_animation_state_set_animation(_state, trackIndex, animation._animation, loop ? -1 : 0);
_bindings.spine_animation_state_set_animation(_state, trackIndex, animation._animation, loop ? -1 : 0);
if (entry.address == nullptr.address) throw Exception("Couldn't set animation ${animation.getName()}"); if (entry.address == nullptr.address) throw Exception("Couldn't set animation ${animation.getName()}");
return TrackEntry._(entry, this); return TrackEntry._(entry, this);
} }
@ -3178,16 +3137,14 @@ class AnimationState {
/// after AnimationState.Dispose /// after AnimationState.Dispose
TrackEntry addAnimationByName(int trackIndex, String animationName, bool loop, double delay) { TrackEntry addAnimationByName(int trackIndex, String animationName, bool loop, double delay) {
final animation = animationName.toNativeUtf8(allocator: _allocator); final animation = animationName.toNativeUtf8(allocator: _allocator);
final entry = _bindings.spine_animation_state_add_animation_by_name( final entry = _bindings.spine_animation_state_add_animation_by_name(_state, trackIndex, animation.cast(), loop ? -1 : 0, delay);
_state, trackIndex, animation.cast(), loop ? -1 : 0, delay);
_allocator.free(animation); _allocator.free(animation);
if (entry.address == nullptr.address) throw Exception("Couldn't add animation $animationName"); if (entry.address == nullptr.address) throw Exception("Couldn't add animation $animationName");
return TrackEntry._(entry, this); return TrackEntry._(entry, this);
} }
TrackEntry addAnimation(int trackIndex, Animation animation, bool loop, double delay) { TrackEntry addAnimation(int trackIndex, Animation animation, bool loop, double delay) {
final entry = final entry = _bindings.spine_animation_state_add_animation(_state, trackIndex, animation._animation, loop ? -1 : 0, delay);
_bindings.spine_animation_state_add_animation(_state, trackIndex, animation._animation, loop ? -1 : 0, delay);
if (entry.address == nullptr.address) throw Exception("Couldn't add animation ${animation.getName()}"); if (entry.address == nullptr.address) throw Exception("Couldn't add animation ${animation.getName()}");
return TrackEntry._(entry, this); return TrackEntry._(entry, this);
} }
@ -3258,7 +3215,8 @@ class SkeletonDrawable {
_drawable = _bindings.spine_skeleton_drawable_create(skeletonData._data); _drawable = _bindings.spine_skeleton_drawable_create(skeletonData._data);
skeleton = Skeleton._(_bindings.spine_skeleton_drawable_get_skeleton(_drawable)); skeleton = Skeleton._(_bindings.spine_skeleton_drawable_get_skeleton(_drawable));
animationStateData = AnimationStateData._(_bindings.spine_skeleton_drawable_get_animation_state_data(_drawable)); animationStateData = AnimationStateData._(_bindings.spine_skeleton_drawable_get_animation_state_data(_drawable));
animationState = AnimationState._(_bindings.spine_skeleton_drawable_get_animation_state(_drawable), _bindings.spine_skeleton_drawable_get_animation_state_events(_drawable)); animationState = AnimationState._(_bindings.spine_skeleton_drawable_get_animation_state(_drawable),
_bindings.spine_skeleton_drawable_get_animation_state_events(_drawable));
skeleton.updateWorldTransform(); skeleton.updateWorldTransform();
} }
@ -3303,8 +3261,7 @@ class SkeletonDrawable {
void renderToCanvas(Canvas canvas) { void renderToCanvas(Canvas canvas) {
var commands = render(); var commands = render();
for (final cmd in commands) { for (final cmd in commands) {
canvas.drawVertices( canvas.drawVertices(cmd.vertices, rendering.BlendMode.modulate, atlas.atlasPagePaints[cmd.atlasPageIndex]);
cmd.vertices, rendering.BlendMode.modulate, atlas.atlasPagePaints[cmd.atlasPageIndex]);
} }
} }
@ -3335,7 +3292,10 @@ class SkeletonDrawable {
Future<RawImageData> renderToRawImageData(double width, double height) async { Future<RawImageData> renderToRawImageData(double width, double height) async {
final recorder = renderToPictureRecorder(width, height); final recorder = renderToPictureRecorder(width, height);
var rawImageData = (await (await recorder.endRecording().toImage(width.toInt(), height.toInt())).toByteData(format: ImageByteFormat.rawRgba))!.buffer.asUint8List(); var rawImageData =
(await (await recorder.endRecording().toImage(width.toInt(), height.toInt())).toByteData(format: ImageByteFormat.rawRgba))!
.buffer
.asUint8List();
return RawImageData(rawImageData, width.toInt(), height.toInt()); return RawImageData(rawImageData, width.toInt(), height.toInt());
} }
@ -3376,20 +3336,14 @@ class RenderCommand {
// is copied, so it doesn't matter that we free up the underlying memory on the next // is copied, so it doesn't matter that we free up the underlying memory on the next
// render call. See the implementation of Vertices.raw() here: // render call. See the implementation of Vertices.raw() here:
// https://github.com/flutter/engine/blob/5c60785b802ad2c8b8899608d949342d5c624952/lib/ui/painting/vertices.cc#L21 // https://github.com/flutter/engine/blob/5c60785b802ad2c8b8899608d949342d5c624952/lib/ui/painting/vertices.cc#L21
vertices = Vertices.raw(VertexMode.triangles, positions, vertices = Vertices.raw(VertexMode.triangles, positions, textureCoordinates: uvs, colors: colors, indices: indices);
textureCoordinates: uvs,
colors: colors,
indices: indices);
} else { } else {
// On the web, rendering is done through CanvasKit, which requires copies of the native data. // On the web, rendering is done through CanvasKit, which requires copies of the native data.
final positionsCopy = Float32List.fromList(positions); final positionsCopy = Float32List.fromList(positions);
final uvsCopy = Float32List.fromList(uvs); final uvsCopy = Float32List.fromList(uvs);
final colorsCopy = Int32List.fromList(colors); final colorsCopy = Int32List.fromList(colors);
final indicesCopy = Uint16List.fromList(indices); final indicesCopy = Uint16List.fromList(indices);
vertices = Vertices.raw(VertexMode.triangles, positionsCopy, vertices = Vertices.raw(VertexMode.triangles, positionsCopy, textureCoordinates: uvsCopy, colors: colorsCopy, indices: indicesCopy);
textureCoordinates: uvsCopy,
colors: colorsCopy,
indices: indicesCopy);
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,8 @@ class SpineWidgetController {
final void Function(SpineWidgetController controller, Canvas canvas)? onBeforePaint; final void Function(SpineWidgetController controller, Canvas canvas)? onBeforePaint;
final void Function(SpineWidgetController controller, Canvas canvas, List<RenderCommand> commands)? onAfterPaint; final void Function(SpineWidgetController controller, Canvas canvas, List<RenderCommand> commands)? onAfterPaint;
SpineWidgetController({this.onInitialized, this.onBeforeUpdateWorldTransforms, this.onAfterUpdateWorldTransforms, this.onBeforePaint, this.onAfterPaint}); SpineWidgetController(
{this.onInitialized, this.onBeforeUpdateWorldTransforms, this.onAfterUpdateWorldTransforms, this.onBeforePaint, this.onAfterPaint});
void _initialize(SkeletonDrawable drawable) { void _initialize(SkeletonDrawable drawable) {
if (_drawable != null) throw Exception("SpineWidgetController already initialized. A controller can only be used with one widget."); if (_drawable != null) throw Exception("SpineWidgetController already initialized. A controller can only be used with one widget.");
@ -24,7 +25,7 @@ class SpineWidgetController {
onInitialized?.call(this); onInitialized?.call(this);
} }
Atlas get atlas { Atlas get atlas {
if (_drawable == null) throw Exception("Controller is not initialized yet."); if (_drawable == null) throw Exception("Controller is not initialized yet.");
return _drawable!.atlas; return _drawable!.atlas;
} }
@ -46,7 +47,7 @@ class SpineWidgetController {
Skeleton get skeleton { Skeleton get skeleton {
if (_drawable == null) throw Exception("Controller is not initialized yet."); if (_drawable == null) throw Exception("Controller is not initialized yet.");
return _drawable!.skeleton; return _drawable!.skeleton;
} }
SkeletonDrawable get drawable { SkeletonDrawable get drawable {
@ -101,8 +102,8 @@ class SkinAndAnimationBounds extends BoundsProvider {
final String? animation; final String? animation;
final double stepTime; final double stepTime;
SkinAndAnimationBounds({List<String>? skins, this.animation, this.stepTime = 0.1}) : SkinAndAnimationBounds({List<String>? skins, this.animation, this.stepTime = 0.1})
skins = skins == null || skins.isEmpty? ["default"] : skins; : skins = skins == null || skins.isEmpty ? ["default"] : skins;
@override @override
Bounds computeBounds(SkeletonDrawable drawable) { Bounds computeBounds(SkeletonDrawable drawable) {
@ -169,7 +170,8 @@ class SpineWidget extends StatefulWidget {
final BoundsProvider _boundsProvider; final BoundsProvider _boundsProvider;
final bool _sizedByBounds; final bool _sizedByBounds;
SpineWidget.asset(this._skeletonFile, this._atlasFile, this._controller, {AssetBundle? bundle, BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) SpineWidget.asset(this._skeletonFile, this._atlasFile, this._controller,
{AssetBundle? bundle, BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key})
: _assetType = AssetType.asset, : _assetType = AssetType.asset,
_fit = fit ?? BoxFit.contain, _fit = fit ?? BoxFit.contain,
_alignment = alignment ?? Alignment.center, _alignment = alignment ?? Alignment.center,
@ -178,7 +180,8 @@ class SpineWidget extends StatefulWidget {
_drawable = null, _drawable = null,
_bundle = bundle ?? rootBundle; _bundle = bundle ?? rootBundle;
const SpineWidget.file(this._skeletonFile, this._atlasFile, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) const SpineWidget.file(this._skeletonFile, this._atlasFile, this._controller,
{BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key})
: _assetType = AssetType.file, : _assetType = AssetType.file,
_bundle = null, _bundle = null,
_fit = fit ?? BoxFit.contain, _fit = fit ?? BoxFit.contain,
@ -187,7 +190,8 @@ class SpineWidget extends StatefulWidget {
_sizedByBounds = sizedByBounds ?? false, _sizedByBounds = sizedByBounds ?? false,
_drawable = null; _drawable = null;
const SpineWidget.http(this._skeletonFile, this._atlasFile, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) const SpineWidget.http(this._skeletonFile, this._atlasFile, this._controller,
{BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key})
: _assetType = AssetType.http, : _assetType = AssetType.http,
_bundle = null, _bundle = null,
_fit = fit ?? BoxFit.contain, _fit = fit ?? BoxFit.contain,
@ -196,7 +200,8 @@ class SpineWidget extends StatefulWidget {
_sizedByBounds = sizedByBounds ?? false, _sizedByBounds = sizedByBounds ?? false,
_drawable = null; _drawable = null;
const SpineWidget.drawable(this._drawable, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) const SpineWidget.drawable(this._drawable, this._controller,
{BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key})
: _assetType = AssetType.drawable, : _assetType = AssetType.drawable,
_bundle = null, _bundle = null,
_fit = fit ?? BoxFit.contain, _fit = fit ?? BoxFit.contain,
@ -250,7 +255,8 @@ class _SpineWidgetState extends State<SpineWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_drawable != null) { if (_drawable != null) {
return _SpineRenderObjectWidget(_drawable!, widget._controller, widget._fit, widget._alignment, _computedBounds, widget._sizedByBounds); return _SpineRenderObjectWidget(
_drawable!, widget._controller, widget._fit, widget._alignment, _computedBounds, widget._sizedByBounds);
} else { } else {
return const SizedBox(); return const SizedBox();
} }
@ -297,6 +303,7 @@ class _SpineRenderObject extends RenderBox {
Alignment _alignment; Alignment _alignment;
Bounds _bounds; Bounds _bounds;
bool _sizedByBounds; bool _sizedByBounds;
_SpineRenderObject(this._skeletonDrawable, this._controller, this._fit, this._alignment, this._bounds, this._sizedByBounds); _SpineRenderObject(this._skeletonDrawable, this._controller, this._fit, this._alignment, this._bounds, this._sizedByBounds);
set skeletonDrawable(SkeletonDrawable skeletonDrawable) { set skeletonDrawable(SkeletonDrawable skeletonDrawable) {
@ -389,7 +396,9 @@ class _SpineRenderObject extends RenderBox {
} }
Size _computeConstrainedSize(BoxConstraints constraints) { Size _computeConstrainedSize(BoxConstraints constraints) {
return sizedByParent ? constraints.smallest : constraints.constrainSizeAndAttemptToPreserveAspectRatio(Size(_bounds.width, _bounds.height)); return sizedByParent
? constraints.smallest
: constraints.constrainSizeAndAttemptToPreserveAspectRatio(Size(_bounds.width, _bounds.height));
} }
@override @override