[flutter] Fix linter warnings and errors

This commit is contained in:
Mario Zechner 2022-12-06 08:58:24 +01:00
parent 577a36a2c5
commit de030c8e8c
10 changed files with 69 additions and 81 deletions

View File

@ -8,9 +8,6 @@ class AnimationStateEvents extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
reportLeaks(); reportLeaks();
final controller = SpineWidgetController(onInitialized: (controller) { final controller = SpineWidgetController(onInitialized: (controller) {
for (final bone in controller.skeleton.getBones()) {
print(bone);
}
controller.skeleton.setScaleX(0.5); controller.skeleton.setScaleX(0.5);
controller.skeleton.setScaleY(0.5); controller.skeleton.setScaleY(0.5);
controller.skeleton.findSlot("gun")?.setColor(Color(1, 0, 0, 1)); controller.skeleton.findSlot("gun")?.setColor(Color(1, 0, 0, 1));
@ -23,7 +20,7 @@ class AnimationStateEvents extends StatelessWidget {
print("Run animation event $type"); print("Run animation event $type");
}); });
controller.animationState.setListener((type, trackEntry, event) { 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()} }"); print("User event: { name: ${event?.getData().getName()}, intValue: ${event?.getIntValue()}, floatValue: intValue: ${event?.getFloatValue()}, stringValue: ${event?.getStringValue()} }");
} }
}); });

View File

@ -1,10 +1,6 @@
import 'dart:math';
import 'dart:ui' as ui;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/painting.dart' as painting; import 'package:flutter/painting.dart' as painting;
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart'; import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flutter/services.dart';
import 'package:raw_image_provider/raw_image_provider.dart'; import 'package:raw_image_provider/raw_image_provider.dart';
class DressUp extends StatefulWidget { class DressUp extends StatefulWidget {
@ -83,7 +79,7 @@ class DressUpState extends State<DressUp> {
// Does not work on web. // Does not work on web.
//: ColorFiltered(colorFilter: const ColorFilter.mode(Colors.grey, painting.BlendMode.saturation,), child: box) //: ColorFiltered(colorFilter: const ColorFilter.mode(Colors.grey, painting.BlendMode.saturation,), child: box)
: Container( : Container(
foregroundDecoration: BoxDecoration( foregroundDecoration: const BoxDecoration(
color: Colors.grey, color: Colors.grey,
backgroundBlendMode: painting.BlendMode.saturation, backgroundBlendMode: painting.BlendMode.saturation,
), ),
@ -104,7 +100,7 @@ class DressUpState extends State<DressUp> {
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
_drawable?.dispose(); _drawable.dispose();
_customSkin?.dispose(); _customSkin?.dispose();
} }
} }

View File

@ -53,11 +53,6 @@ class SpineComponent extends PositionComponent {
if (_ownsDrawable) { if (_ownsDrawable) {
_drawable.dispose(); _drawable.dispose();
} }
@override
void onDetach() {
}
} }
@override @override

View File

@ -63,7 +63,7 @@ class ExampleSelector extends StatelessWidget {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (context) => DebugRendering(), builder: (context) => const DebugRendering(),
), ),
); );
}, },

View File

@ -150,7 +150,7 @@ packages:
source: hosted source: hosted
version: "1.8.2" version: "1.8.2"
raw_image_provider: raw_image_provider:
dependency: transitive dependency: "direct main"
description: description:
name: raw_image_provider name: raw_image_provider
sha256: d5b20d69e8a998a4dc846a3d35dca8760121d18b6895233fca52f9055a9a7e8e sha256: d5b20d69e8a998a4dc846a3d35dca8760121d18b6895233fca52f9055a9a7e8e

View File

@ -14,6 +14,7 @@ dependencies:
path: ../ path: ../
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
flame: ^1.4.0 flame: ^1.4.0
raw_image_provider: ^0.2.0
dev_dependencies: dev_dependencies:
flutter_lints: ^2.0.0 flutter_lints: ^2.0.0

View File

@ -13,7 +13,7 @@ headers:
include-directives: include-directives:
- 'src/spine_flutter.h' - 'src/spine_flutter.h'
preamble: | 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: camel_case_types
// ignore_for_file: non_constant_identifier_names // ignore_for_file: non_constant_identifier_names
comments: comments:

View File

@ -455,10 +455,10 @@ class SkeletonData {
} }
enum BlendMode { enum BlendMode {
Normal(0), normal(0),
Additive(1), additive(1),
Multiply(2), multiply(2),
Screen(3); screen(3);
final int value; final int value;
@ -466,11 +466,11 @@ enum BlendMode {
} }
enum TransformMode { enum TransformMode {
Normal(0), normal(0),
OnlyTranslation(1), onlyTranslation(1),
NoRotationOrReflection(2), noRotationOrReflection(2),
NoScale(3), noScale(3),
NoScaleOrReflection(4); noScaleOrReflection(4);
final int value; final int value;
@ -478,8 +478,8 @@ enum TransformMode {
} }
enum PositionMode { enum PositionMode {
Fixed(0), fixed(0),
Percent(1); percent(1);
final int value; final int value;
@ -487,10 +487,10 @@ enum PositionMode {
} }
enum SpacingMode { enum SpacingMode {
Length(0), length(0),
Fixed(1), fixed(1),
Percent(2), percent(2),
Proportional(3); proportional(3);
final int value; final int value;
@ -498,9 +498,9 @@ enum SpacingMode {
} }
enum RotateMode { enum RotateMode {
Tangent(0), tangent(0),
Chain(1), chain(1),
ChainScale(2); chainScale(2);
final int value; final int value;
@ -1216,12 +1216,12 @@ class Sequence {
} }
enum AttachmentType { enum AttachmentType {
Region(0), region(0),
Mesh(1), mesh(1),
Clipping(2), clipping(2),
BoundingBox(3), boundingBox(3),
Path(4), path(4),
Point(5); point(5);
final int value; final int value;
@ -1246,17 +1246,17 @@ abstract class Attachment<T extends Pointer> {
static Attachment _toSubclass(spine_attachment attachment) { static Attachment _toSubclass(spine_attachment attachment) {
final type = AttachmentType.values[_bindings.spine_attachment_get_type(attachment)]; final type = AttachmentType.values[_bindings.spine_attachment_get_type(attachment)];
switch (type) { switch (type) {
case AttachmentType.Region: case AttachmentType.region:
return RegionAttachment._(attachment.cast()); return RegionAttachment._(attachment.cast());
case AttachmentType.Mesh: case AttachmentType.mesh:
return MeshAttachment._(attachment.cast()); return MeshAttachment._(attachment.cast());
case AttachmentType.Clipping: case AttachmentType.clipping:
return ClippingAttachment._(attachment.cast()); return ClippingAttachment._(attachment.cast());
case AttachmentType.BoundingBox: case AttachmentType.boundingBox:
return BoundingBoxAttachment._(attachment.cast()); return BoundingBoxAttachment._(attachment.cast());
case AttachmentType.Path: case AttachmentType.path:
return PathAttachment._(attachment.cast()); return PathAttachment._(attachment.cast());
case AttachmentType.Point: case AttachmentType.point:
return PointAttachment._(attachment.cast()); return PointAttachment._(attachment.cast());
} }
} }
@ -1661,7 +1661,7 @@ class Skin {
Skin._(this._skin) : _isCustomSkin = false; Skin._(this._skin) : _isCustomSkin = false;
Skin.new(String name) { Skin(String name) {
final nativeName = name.toNativeUtf8(allocator: _allocator); final nativeName = name.toNativeUtf8(allocator: _allocator);
_skin = _bindings.spine_skin_create(nativeName.cast()); _skin = _bindings.spine_skin_create(nativeName.cast());
_allocator.free(nativeName); _allocator.free(nativeName);
@ -2613,10 +2613,10 @@ class Animation {
} }
enum MixBlend { enum MixBlend {
Setup(0), setup(0),
First(1), first(1),
Replace(2), replace(2),
Add(3); add(3);
final int value; 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 { class EventData {
final spine_event_data _data; final spine_event_data _data;
@ -3016,7 +3016,7 @@ class Event {
typedef AnimationStateListener = void Function(EventType type, TrackEntry entry, Event? event); typedef AnimationStateListener = void Function(EventType type, TrackEntry entry, Event? event);
class AnimationStateData { class AnimationStateData {
spine_animation_state_data _data; final spine_animation_state_data _data;
AnimationStateData._(this._data); AnimationStateData._(this._data);
@ -3089,22 +3089,22 @@ class AnimationState {
late final EventType type; late final EventType type;
switch (_bindings.spine_animation_state_events_get_event_type(_events, i)) { switch (_bindings.spine_animation_state_events_get_event_type(_events, i)) {
case 0: case 0:
type = EventType.Start; type = EventType.start;
break; break;
case 1: case 1:
type = EventType.Interrupt; type = EventType.interrupt;
break; break;
case 2: case 2:
type = EventType.End; type = EventType.end;
break; break;
case 3: case 3:
type = EventType.Complete; type = EventType.complete;
break; break;
case 4: case 4:
type = EventType.Dispose; type = EventType.dispose;
break; break;
case 5: case 5:
type = EventType.Event; type = EventType.event;
break; break;
} }
final nativeEntry = _bindings.spine_animation_state_events_get_track_entry(_events, i); final nativeEntry = _bindings.spine_animation_state_events_get_track_entry(_events, i);
@ -3117,7 +3117,7 @@ class AnimationState {
if (_stateListener != null) { if (_stateListener != null) {
_stateListener?.call(type, entry, event); _stateListener?.call(type, entry, event);
} }
if (type == EventType.Dispose) { if (type == EventType.dispose) {
_bindings.spine_animation_state_dispose_track_entry(_state, nativeEntry); _bindings.spine_animation_state_dispose_track_entry(_state, nativeEntry);
} }
} }

View File

@ -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: camel_case_types
// ignore_for_file: non_constant_identifier_names // ignore_for_file: non_constant_identifier_names

View File

@ -68,7 +68,7 @@ class SpineWidgetController {
} }
} }
enum AssetType { Asset, File, Http, Drawable } enum AssetType { asset, file, http, drawable }
abstract class BoundsProvider { abstract class BoundsProvider {
const BoundsProvider(); const BoundsProvider();
@ -159,7 +159,7 @@ class ComputedBounds extends BoundsProvider {
class SpineWidget extends StatefulWidget { class SpineWidget extends StatefulWidget {
final AssetType _assetType; final AssetType _assetType;
AssetBundle? _bundle; final AssetBundle? _bundle;
final String? _skeletonFile; final String? _skeletonFile;
final String? _atlasFile; final String? _atlasFile;
final SkeletonDrawable? _drawable; final SkeletonDrawable? _drawable;
@ -170,17 +170,16 @@ class SpineWidget extends StatefulWidget {
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,
_boundsProvider = boundsProvider ?? const SetupPoseBounds(), _boundsProvider = boundsProvider ?? const SetupPoseBounds(),
_sizedByBounds = sizedByBounds ?? false, _sizedByBounds = sizedByBounds ?? false,
_drawable = null { _drawable = null,
_bundle = bundle ?? rootBundle; _bundle = bundle ?? rootBundle;
}
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,
_alignment = alignment ?? Alignment.center, _alignment = alignment ?? Alignment.center,
@ -188,8 +187,8 @@ class SpineWidget extends StatefulWidget {
_sizedByBounds = sizedByBounds ?? false, _sizedByBounds = sizedByBounds ?? false,
_drawable = null; _drawable = null;
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,
_alignment = alignment ?? Alignment.center, _alignment = alignment ?? Alignment.center,
@ -197,8 +196,8 @@ class SpineWidget extends StatefulWidget {
_sizedByBounds = sizedByBounds ?? false, _sizedByBounds = sizedByBounds ?? false,
_drawable = null; _drawable = null;
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,
_alignment = alignment ?? Alignment.center, _alignment = alignment ?? Alignment.center,
@ -218,7 +217,7 @@ class _SpineWidgetState extends State<SpineWidget> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget._assetType == AssetType.Drawable) { if (widget._assetType == AssetType.drawable) {
loadDrawable(widget._drawable!); loadDrawable(widget._drawable!);
} else { } else {
loadFromAsset(widget._bundle, widget._skeletonFile!, widget._atlasFile!, widget._assetType); loadFromAsset(widget._bundle, widget._skeletonFile!, widget._atlasFile!, widget._assetType);
@ -234,16 +233,16 @@ class _SpineWidgetState extends State<SpineWidget> {
void loadFromAsset(AssetBundle? bundle, String atlasFile, String skeletonFile, AssetType assetType) async { void loadFromAsset(AssetBundle? bundle, String atlasFile, String skeletonFile, AssetType assetType) async {
switch (assetType) { switch (assetType) {
case AssetType.Asset: case AssetType.asset:
loadDrawable(await SkeletonDrawable.fromAsset(atlasFile, skeletonFile, bundle: bundle)); loadDrawable(await SkeletonDrawable.fromAsset(atlasFile, skeletonFile, bundle: bundle));
break; break;
case AssetType.File: case AssetType.file:
loadDrawable(await SkeletonDrawable.fromFile(atlasFile, skeletonFile)); loadDrawable(await SkeletonDrawable.fromFile(atlasFile, skeletonFile));
break; break;
case AssetType.Http: case AssetType.http:
loadDrawable(await SkeletonDrawable.fromHttp(atlasFile, skeletonFile)); loadDrawable(await SkeletonDrawable.fromHttp(atlasFile, skeletonFile));
break; break;
case AssetType.Drawable: case AssetType.drawable:
throw Exception("Drawable can not be loaded via loadFromAsset()."); throw Exception("Drawable can not be loaded via loadFromAsset().");
} }
} }
@ -291,7 +290,7 @@ class _SpineRenderObjectWidget extends LeafRenderObjectWidget {
class _SpineRenderObject extends RenderBox { class _SpineRenderObject extends RenderBox {
SkeletonDrawable _skeletonDrawable; SkeletonDrawable _skeletonDrawable;
SpineWidgetController _controller; final SpineWidgetController _controller;
double _deltaTime = 0; double _deltaTime = 0;
final Stopwatch _stopwatch = Stopwatch(); final Stopwatch _stopwatch = Stopwatch();
BoxFit _fit; BoxFit _fit;