From de030c8e8c92bc83a4803966c29f3d0a4d71b6bf Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 6 Dec 2022 08:58:24 +0100 Subject: [PATCH] [flutter] Fix linter warnings and errors --- .../example/lib/animation_state_events.dart | 5 +- spine-flutter/example/lib/dress_up.dart | 8 +- spine-flutter/example/lib/flame_example.dart | 5 -- spine-flutter/example/lib/main.dart | 2 +- spine-flutter/example/pubspec.lock | 2 +- spine-flutter/example/pubspec.yaml | 1 + spine-flutter/ffigen.yaml | 2 +- spine-flutter/lib/spine_flutter.dart | 88 +++++++++---------- .../lib/spine_flutter_bindings_generated.dart | 2 +- spine-flutter/lib/spine_widget.dart | 35 ++++---- 10 files changed, 69 insertions(+), 81 deletions(-) diff --git a/spine-flutter/example/lib/animation_state_events.dart b/spine-flutter/example/lib/animation_state_events.dart index 9e0e435be..94ea202ce 100644 --- a/spine-flutter/example/lib/animation_state_events.dart +++ b/spine-flutter/example/lib/animation_state_events.dart @@ -8,9 +8,6 @@ class AnimationStateEvents extends StatelessWidget { Widget build(BuildContext context) { reportLeaks(); final controller = SpineWidgetController(onInitialized: (controller) { - for (final bone in controller.skeleton.getBones()) { - print(bone); - } controller.skeleton.setScaleX(0.5); controller.skeleton.setScaleY(0.5); controller.skeleton.findSlot("gun")?.setColor(Color(1, 0, 0, 1)); @@ -23,7 +20,7 @@ class AnimationStateEvents extends StatelessWidget { print("Run animation event $type"); }); controller.animationState.setListener((type, trackEntry, event) { - if (type == EventType.Event) { + if (type == EventType.event) { print("User event: { name: ${event?.getData().getName()}, intValue: ${event?.getIntValue()}, floatValue: intValue: ${event?.getFloatValue()}, stringValue: ${event?.getStringValue()} }"); } }); diff --git a/spine-flutter/example/lib/dress_up.dart b/spine-flutter/example/lib/dress_up.dart index 90ecbd6a4..b4b1090c7 100644 --- a/spine-flutter/example/lib/dress_up.dart +++ b/spine-flutter/example/lib/dress_up.dart @@ -1,10 +1,6 @@ -import 'dart:math'; -import 'dart:ui' as ui; - import 'package:flutter/material.dart'; import 'package:flutter/painting.dart' as painting; import 'package:esotericsoftware_spine_flutter/spine_flutter.dart'; -import 'package:flutter/services.dart'; import 'package:raw_image_provider/raw_image_provider.dart'; class DressUp extends StatefulWidget { @@ -83,7 +79,7 @@ class DressUpState extends State { // Does not work on web. //: ColorFiltered(colorFilter: const ColorFilter.mode(Colors.grey, painting.BlendMode.saturation,), child: box) : Container( - foregroundDecoration: BoxDecoration( + foregroundDecoration: const BoxDecoration( color: Colors.grey, backgroundBlendMode: painting.BlendMode.saturation, ), @@ -104,7 +100,7 @@ class DressUpState extends State { @override void dispose() { super.dispose(); - _drawable?.dispose(); + _drawable.dispose(); _customSkin?.dispose(); } } \ No newline at end of file diff --git a/spine-flutter/example/lib/flame_example.dart b/spine-flutter/example/lib/flame_example.dart index 9e9c51a61..c383d5a37 100644 --- a/spine-flutter/example/lib/flame_example.dart +++ b/spine-flutter/example/lib/flame_example.dart @@ -53,11 +53,6 @@ class SpineComponent extends PositionComponent { if (_ownsDrawable) { _drawable.dispose(); } - - @override - void onDetach() { - - } } @override diff --git a/spine-flutter/example/lib/main.dart b/spine-flutter/example/lib/main.dart index 907d8b5a1..688d38366 100644 --- a/spine-flutter/example/lib/main.dart +++ b/spine-flutter/example/lib/main.dart @@ -63,7 +63,7 @@ class ExampleSelector extends StatelessWidget { Navigator.push( context, MaterialPageRoute( - builder: (context) => DebugRendering(), + builder: (context) => const DebugRendering(), ), ); }, diff --git a/spine-flutter/example/pubspec.lock b/spine-flutter/example/pubspec.lock index ce1df3a37..0b5a8562f 100644 --- a/spine-flutter/example/pubspec.lock +++ b/spine-flutter/example/pubspec.lock @@ -150,7 +150,7 @@ packages: source: hosted version: "1.8.2" raw_image_provider: - dependency: transitive + dependency: "direct main" description: name: raw_image_provider sha256: d5b20d69e8a998a4dc846a3d35dca8760121d18b6895233fca52f9055a9a7e8e diff --git a/spine-flutter/example/pubspec.yaml b/spine-flutter/example/pubspec.yaml index b86d1c410..a4e73cde3 100644 --- a/spine-flutter/example/pubspec.yaml +++ b/spine-flutter/example/pubspec.yaml @@ -14,6 +14,7 @@ dependencies: path: ../ cupertino_icons: ^1.0.2 flame: ^1.4.0 + raw_image_provider: ^0.2.0 dev_dependencies: flutter_lints: ^2.0.0 diff --git a/spine-flutter/ffigen.yaml b/spine-flutter/ffigen.yaml index 26535428b..d6c9fcac9 100644 --- a/spine-flutter/ffigen.yaml +++ b/spine-flutter/ffigen.yaml @@ -13,7 +13,7 @@ headers: include-directives: - 'src/spine_flutter.h' preamble: | - // ignore_for_file: always_specify_types + // ignore_for_file: always_specify_types, constant_identifier_names // ignore_for_file: camel_case_types // ignore_for_file: non_constant_identifier_names comments: diff --git a/spine-flutter/lib/spine_flutter.dart b/spine-flutter/lib/spine_flutter.dart index 31fb47c2f..9359fb3b8 100644 --- a/spine-flutter/lib/spine_flutter.dart +++ b/spine-flutter/lib/spine_flutter.dart @@ -455,10 +455,10 @@ class SkeletonData { } enum BlendMode { - Normal(0), - Additive(1), - Multiply(2), - Screen(3); + normal(0), + additive(1), + multiply(2), + screen(3); final int value; @@ -466,11 +466,11 @@ enum BlendMode { } enum TransformMode { - Normal(0), - OnlyTranslation(1), - NoRotationOrReflection(2), - NoScale(3), - NoScaleOrReflection(4); + normal(0), + onlyTranslation(1), + noRotationOrReflection(2), + noScale(3), + noScaleOrReflection(4); final int value; @@ -478,8 +478,8 @@ enum TransformMode { } enum PositionMode { - Fixed(0), - Percent(1); + fixed(0), + percent(1); final int value; @@ -487,10 +487,10 @@ enum PositionMode { } enum SpacingMode { - Length(0), - Fixed(1), - Percent(2), - Proportional(3); + length(0), + fixed(1), + percent(2), + proportional(3); final int value; @@ -498,9 +498,9 @@ enum SpacingMode { } enum RotateMode { - Tangent(0), - Chain(1), - ChainScale(2); + tangent(0), + chain(1), + chainScale(2); final int value; @@ -1216,12 +1216,12 @@ class Sequence { } enum AttachmentType { - Region(0), - Mesh(1), - Clipping(2), - BoundingBox(3), - Path(4), - Point(5); + region(0), + mesh(1), + clipping(2), + boundingBox(3), + path(4), + point(5); final int value; @@ -1246,17 +1246,17 @@ abstract class Attachment { static Attachment _toSubclass(spine_attachment attachment) { final type = AttachmentType.values[_bindings.spine_attachment_get_type(attachment)]; switch (type) { - case AttachmentType.Region: + case AttachmentType.region: return RegionAttachment._(attachment.cast()); - case AttachmentType.Mesh: + case AttachmentType.mesh: return MeshAttachment._(attachment.cast()); - case AttachmentType.Clipping: + case AttachmentType.clipping: return ClippingAttachment._(attachment.cast()); - case AttachmentType.BoundingBox: + case AttachmentType.boundingBox: return BoundingBoxAttachment._(attachment.cast()); - case AttachmentType.Path: + case AttachmentType.path: return PathAttachment._(attachment.cast()); - case AttachmentType.Point: + case AttachmentType.point: return PointAttachment._(attachment.cast()); } } @@ -1661,7 +1661,7 @@ class Skin { Skin._(this._skin) : _isCustomSkin = false; - Skin.new(String name) { + Skin(String name) { final nativeName = name.toNativeUtf8(allocator: _allocator); _skin = _bindings.spine_skin_create(nativeName.cast()); _allocator.free(nativeName); @@ -2613,10 +2613,10 @@ class Animation { } enum MixBlend { - Setup(0), - First(1), - Replace(2), - Add(3); + setup(0), + first(1), + replace(2), + add(3); final int value; @@ -2895,7 +2895,7 @@ class TrackEntry { } } -enum EventType { Start, Interrupt, End, Complete, Dispose, Event } +enum EventType { start, interrupt, end, complete, dispose, event } class EventData { final spine_event_data _data; @@ -3016,7 +3016,7 @@ class Event { typedef AnimationStateListener = void Function(EventType type, TrackEntry entry, Event? event); class AnimationStateData { - spine_animation_state_data _data; + final spine_animation_state_data _data; AnimationStateData._(this._data); @@ -3089,22 +3089,22 @@ class AnimationState { late final EventType type; switch (_bindings.spine_animation_state_events_get_event_type(_events, i)) { case 0: - type = EventType.Start; + type = EventType.start; break; case 1: - type = EventType.Interrupt; + type = EventType.interrupt; break; case 2: - type = EventType.End; + type = EventType.end; break; case 3: - type = EventType.Complete; + type = EventType.complete; break; case 4: - type = EventType.Dispose; + type = EventType.dispose; break; case 5: - type = EventType.Event; + type = EventType.event; break; } final nativeEntry = _bindings.spine_animation_state_events_get_track_entry(_events, i); @@ -3117,7 +3117,7 @@ class AnimationState { if (_stateListener != null) { _stateListener?.call(type, entry, event); } - if (type == EventType.Dispose) { + if (type == EventType.dispose) { _bindings.spine_animation_state_dispose_track_entry(_state, nativeEntry); } } diff --git a/spine-flutter/lib/spine_flutter_bindings_generated.dart b/spine-flutter/lib/spine_flutter_bindings_generated.dart index cf1e46f41..0db4bc448 100644 --- a/spine-flutter/lib/spine_flutter_bindings_generated.dart +++ b/spine-flutter/lib/spine_flutter_bindings_generated.dart @@ -1,4 +1,4 @@ -// ignore_for_file: always_specify_types +// ignore_for_file: always_specify_types, constant_identifier_names // ignore_for_file: camel_case_types // ignore_for_file: non_constant_identifier_names diff --git a/spine-flutter/lib/spine_widget.dart b/spine-flutter/lib/spine_widget.dart index 031dbe299..bd3f2ea1c 100644 --- a/spine-flutter/lib/spine_widget.dart +++ b/spine-flutter/lib/spine_widget.dart @@ -68,7 +68,7 @@ class SpineWidgetController { } } -enum AssetType { Asset, File, Http, Drawable } +enum AssetType { asset, file, http, drawable } abstract class BoundsProvider { const BoundsProvider(); @@ -159,7 +159,7 @@ class ComputedBounds extends BoundsProvider { class SpineWidget extends StatefulWidget { final AssetType _assetType; - AssetBundle? _bundle; + final AssetBundle? _bundle; final String? _skeletonFile; final String? _atlasFile; final SkeletonDrawable? _drawable; @@ -170,17 +170,16 @@ class SpineWidget extends StatefulWidget { final bool _sizedByBounds; 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, _alignment = alignment ?? Alignment.center, _boundsProvider = boundsProvider ?? const SetupPoseBounds(), _sizedByBounds = sizedByBounds ?? false, - _drawable = null { - _bundle = bundle ?? rootBundle; - } + _drawable = null, + _bundle = bundle ?? rootBundle; - SpineWidget.file(this._skeletonFile, this._atlasFile, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) - : _assetType = AssetType.File, + const SpineWidget.file(this._skeletonFile, this._atlasFile, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) + : _assetType = AssetType.file, _bundle = null, _fit = fit ?? BoxFit.contain, _alignment = alignment ?? Alignment.center, @@ -188,8 +187,8 @@ class SpineWidget extends StatefulWidget { _sizedByBounds = sizedByBounds ?? false, _drawable = null; - SpineWidget.http(this._skeletonFile, this._atlasFile, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) - : _assetType = AssetType.Http, + const SpineWidget.http(this._skeletonFile, this._atlasFile, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) + : _assetType = AssetType.http, _bundle = null, _fit = fit ?? BoxFit.contain, _alignment = alignment ?? Alignment.center, @@ -197,8 +196,8 @@ class SpineWidget extends StatefulWidget { _sizedByBounds = sizedByBounds ?? false, _drawable = null; - SpineWidget.drawable(this._drawable, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) - : _assetType = AssetType.Drawable, + const SpineWidget.drawable(this._drawable, this._controller, {BoxFit? fit, Alignment? alignment, BoundsProvider? boundsProvider, bool? sizedByBounds, super.key}) + : _assetType = AssetType.drawable, _bundle = null, _fit = fit ?? BoxFit.contain, _alignment = alignment ?? Alignment.center, @@ -218,7 +217,7 @@ class _SpineWidgetState extends State { @override void initState() { super.initState(); - if (widget._assetType == AssetType.Drawable) { + if (widget._assetType == AssetType.drawable) { loadDrawable(widget._drawable!); } else { loadFromAsset(widget._bundle, widget._skeletonFile!, widget._atlasFile!, widget._assetType); @@ -234,16 +233,16 @@ class _SpineWidgetState extends State { void loadFromAsset(AssetBundle? bundle, String atlasFile, String skeletonFile, AssetType assetType) async { switch (assetType) { - case AssetType.Asset: + case AssetType.asset: loadDrawable(await SkeletonDrawable.fromAsset(atlasFile, skeletonFile, bundle: bundle)); break; - case AssetType.File: + case AssetType.file: loadDrawable(await SkeletonDrawable.fromFile(atlasFile, skeletonFile)); break; - case AssetType.Http: + case AssetType.http: loadDrawable(await SkeletonDrawable.fromHttp(atlasFile, skeletonFile)); break; - case AssetType.Drawable: + case AssetType.drawable: throw Exception("Drawable can not be loaded via loadFromAsset()."); } } @@ -291,7 +290,7 @@ class _SpineRenderObjectWidget extends LeafRenderObjectWidget { class _SpineRenderObject extends RenderBox { SkeletonDrawable _skeletonDrawable; - SpineWidgetController _controller; + final SpineWidgetController _controller; double _deltaTime = 0; final Stopwatch _stopwatch = Stopwatch(); BoxFit _fit;