[flutter] Formatting.

This commit is contained in:
Mario Zechner 2022-12-06 10:04:51 +01:00
parent 4b47af1e66
commit 1cf95f49d2
10 changed files with 206 additions and 222 deletions

View File

@ -1,6 +1,6 @@
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flutter/material.dart';
class AnimationStateEvents extends StatelessWidget {
const AnimationStateEvents({Key? key}) : super(key: key);
@ -22,7 +22,8 @@ class AnimationStateEvents extends StatelessWidget {
});
controller.animationState.setListener((type, trackEntry, 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()} }");
}
});
print("Current: ${controller.animationState.getCurrent(0)?.getAnimation().getName()}");
@ -30,14 +31,9 @@ class AnimationStateEvents extends StatelessWidget {
return Scaffold(
appBar: AppBar(title: const Text('Spineboy')),
body: Column(
children: [
body: Column(children: [
const Text("See output in console!"),
Expanded(
child: SpineWidget.asset("assets/spineboy.atlas", "assets/spineboy-pro.skel", controller)
)
]
)
);
Expanded(child: SpineWidget.asset("assets/spineboy.atlas", "assets/spineboy-pro.skel", controller))
]));
}
}

View File

@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flutter/material.dart';
class DebugRendering extends StatelessWidget {
const DebugRendering({Key? key}) : super(key: key);
@ -9,14 +9,11 @@ class DebugRendering extends StatelessWidget {
reportLeaks();
const debugRenderer = DebugRenderer();
final controller = SpineWidgetController(
onInitialized: (controller) {
final controller = SpineWidgetController(onInitialized: (controller) {
controller.animationState.setAnimationByName(0, "walk", true);
},
onAfterPaint: (controller, canvas, commands) {
}, onAfterPaint: (controller, canvas, commands) {
debugRenderer.render(controller.drawable, canvas, commands);
}
);
});
return Scaffold(
appBar: AppBar(title: const Text('Debug Renderer')),

View File

@ -1,6 +1,6 @@
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart' as painting;
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:raw_image_provider/raw_image_provider.dart';
class DressUp extends StatefulWidget {
@ -61,10 +61,10 @@ class DressUpState extends State<DressUp> {
appBar: AppBar(title: const Text('Dress Up')),
body: _skinImages.isEmpty
? const SizedBox()
: Row(
children: [
SizedBox(width: thumbnailSize, child:
ListView(
: Row(children: [
SizedBox(
width: thumbnailSize,
child: ListView(
children: _skinImages.keys.map((skinName) {
var rawImageData = _skinImages[skinName]!;
var image = Image(image: RawImageProvider(rawImageData));
@ -83,18 +83,16 @@ class DressUpState extends State<DressUp> {
color: Colors.grey,
backgroundBlendMode: painting.BlendMode.saturation,
),
child: box
)
);
}).toList()
),
child: box));
}).toList()),
),
Expanded(
child: SpineWidget.drawable(_drawable, controller, boundsProvider: SkinAndAnimationBounds(skins: ["full-skins/girl"]),)
)
]
)
);
child: SpineWidget.drawable(
_drawable,
controller,
boundsProvider: SkinAndAnimationBounds(skins: ["full-skins/girl"]),
))
]));
}
@override

View File

@ -1,9 +1,9 @@
import 'dart:math';
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
class SpineComponent extends PositionComponent {
final BoundsProvider _boundsProvider;
@ -11,7 +11,8 @@ class SpineComponent extends PositionComponent {
late final Bounds _bounds;
final bool _ownsDrawable;
SpineComponent(this._drawable, {
SpineComponent(
this._drawable, {
bool ownsDrawable = true,
BoundsProvider boundsProvider = const SetupPoseBounds(),
super.position,
@ -20,16 +21,18 @@ class SpineComponent extends PositionComponent {
Anchor super.anchor = Anchor.topLeft,
super.children,
super.priority,
}) :
_ownsDrawable = ownsDrawable,
}) : _ownsDrawable = ownsDrawable,
_boundsProvider = boundsProvider {
_drawable.update(0);
_bounds = _boundsProvider.computeBounds(_drawable);
size = Vector2(_bounds.width, _bounds.height);
}
static Future<SpineComponent> fromAssets(String atlasFile, String skeletonFile, {
AssetBundle? bundle, BoundsProvider boundsProvider = const SetupPoseBounds(),
static Future<SpineComponent> fromAssets(
String atlasFile,
String skeletonFile, {
AssetBundle? bundle,
BoundsProvider boundsProvider = const SetupPoseBounds(),
Vector2? position,
Vector2? scale,
double angle = 0.0,
@ -37,8 +40,7 @@ class SpineComponent extends PositionComponent {
Iterable<Component>? children,
int? priority,
}) async {
return SpineComponent(
await SkeletonDrawable.fromAsset(atlasFile, skeletonFile, bundle: bundle),
return SpineComponent(await SkeletonDrawable.fromAsset(atlasFile, skeletonFile, bundle: bundle),
ownsDrawable: true,
boundsProvider: boundsProvider,
position: position,
@ -69,7 +71,9 @@ class SpineComponent extends PositionComponent {
}
get animationState => _drawable.animationState;
get animationStateData => _drawable.animationStateData;
get skeleton => _drawable.skeleton;
}
@ -81,12 +85,8 @@ class SimpleFlameExample extends FlameGame {
// Load the Spineboy atlas and skeleton data from asset files
// and create a SpineComponent from them, scaled down and
// centered on the screen
spineboy = await SpineComponent.fromAssets(
"assets/spineboy.atlas", "assets/spineboy-pro.skel",
scale: Vector2(0.4, 0.4),
anchor: Anchor.center,
position: Vector2(size.x / 2, size.y / 2)
);
spineboy = await SpineComponent.fromAssets("assets/spineboy.atlas", "assets/spineboy-pro.skel",
scale: Vector2(0.4, 0.4), anchor: Anchor.center, position: Vector2(size.x / 2, size.y / 2));
// Set the "walk" animation on track 0 in looping mode
spineboy.animationState.setAnimationByName(0, "walk", true);
@ -119,11 +119,7 @@ class PreloadAndShareSpineDataExample extends FlameGame {
final drawable = SkeletonDrawable(cachedAtlas, cachedSkeletonData, false);
final scale = 0.1 + rng.nextDouble() * 0.2;
final position = Vector2(rng.nextDouble() * size.x, rng.nextDouble() * size.y);
final spineboy = SpineComponent(
drawable,
scale: Vector2(scale, scale),
position: position
);
final spineboy = SpineComponent(drawable, scale: Vector2(scale, scale), position: position);
spineboy.animationState.setAnimationByName(0, "walk", true);
spineboys.add(spineboy);
await add(spineboy);
@ -145,13 +141,11 @@ class PreloadAndShareSpineDataExample extends FlameGame {
class SpineFlameGameWidget extends StatelessWidget {
final FlameGame game;
const SpineFlameGameWidget(this.game, {super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Flame Integration')),
body: GameWidget(game: game)
);
return Scaffold(appBar: AppBar(title: const Text('Flame Integration')), body: GameWidget(game: game));
}
}

View File

@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flutter/material.dart';
class IkFollowing extends StatefulWidget {
const IkFollowing({Key? key}) : super(key: key);

View File

@ -1,13 +1,13 @@
import 'package:flutter/material.dart';
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flutter/material.dart';
import 'package:spine_flutter_example/debug_rendering.dart';
import 'flame_example.dart';
import 'simple_animation.dart';
import 'animation_state_events.dart';
import 'pause_play_animation.dart';
import 'dress_up.dart';
import 'flame_example.dart';
import 'ik_following.dart';
import 'pause_play_animation.dart';
import 'simple_animation.dart';
class ExampleSelector extends StatelessWidget {
const ExampleSelector({super.key});
@ -18,9 +18,7 @@ class ExampleSelector extends StatelessWidget {
return Scaffold(
appBar: AppBar(title: const Text('Spine Examples')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
child: Column(mainAxisSize: MainAxisSize.min, children: [
ElevatedButton(
child: const Text('Simple Animation'),
onPressed: () {
@ -117,18 +115,12 @@ class ExampleSelector extends StatelessWidget {
},
),
spacer
]
)
)
);
])));
}
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await initSpineFlutter(enableMemoryDebugging: false);
runApp(const MaterialApp(
title: "Spine Examples",
home: ExampleSelector()
));
runApp(const MaterialApp(title: "Spine Examples", home: ExampleSelector()));
}

View File

@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flutter/material.dart';
class PlayPauseAnimation extends StatefulWidget {
const PlayPauseAnimation({Key? key}) : super(key: key);
@ -33,7 +33,12 @@ class PlayPauseAnimationState extends State<PlayPauseAnimation> {
return Scaffold(
appBar: AppBar(title: const Text('Play/Pause')),
body: SpineWidget.asset("assets/dragon.atlas", "assets/dragon-ess.skel", controller, boundsProvider: SkinAndAnimationBounds(animation: "flying"),),
body: SpineWidget.asset(
"assets/dragon.atlas",
"assets/dragon-ess.skel",
controller,
boundsProvider: SkinAndAnimationBounds(animation: "flying"),
),
floatingActionButton: FloatingActionButton(
onPressed: _togglePlay,
child: Icon(isPlaying ? Icons.pause : Icons.play_arrow),

View File

@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:esotericsoftware_spine_flutter/spine_flutter.dart';
import 'package:flutter/material.dart';
class SimpleAnimation extends StatelessWidget {
const SimpleAnimation({Key? key}) : super(key: key);

View File

@ -3,9 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:convert';
import 'ffi_proxy.dart';
import 'dart:typed_data';
import 'ffi_proxy.dart';
/// The contents of a native zero-terminated array of UTF-8 code units.
///
/// The Utf8 type itself has no functionality, it's only intended to be used
@ -57,8 +58,7 @@ extension Utf8Pointer on Pointer<Utf8> {
void _ensureNotNullptr(String operation) {
if (this == nullptr) {
throw UnsupportedError(
"Operation '$operation' not allowed on a 'nullptr'.");
throw UnsupportedError("Operation '$operation' not allowed on a 'nullptr'.");
}
}
}

View File

@ -3,6 +3,7 @@ import 'package:flutter/services.dart';
import 'package:inject_js/inject_js.dart' as js;
import 'package:web_ffi_fork/web_ffi.dart';
import 'package:web_ffi_fork/web_ffi_modules.dart';
import 'spine_flutter_bindings_generated.dart';
Module? _module;
@ -61,7 +62,8 @@ Future<SpineFlutterFFI> initSpineFlutterFFI() async {
registerOpaqueType<spine_skin_entries_wrapper>();
await js.importLibrary('assets/packages/esotericsoftware_spine_flutter/lib/assets/libspine_flutter.js');
Uint8List wasmBinaries = (await rootBundle.load('packages/esotericsoftware_spine_flutter/lib/assets/libspine_flutter.wasm')).buffer.asUint8List();
Uint8List wasmBinaries =
(await rootBundle.load('packages/esotericsoftware_spine_flutter/lib/assets/libspine_flutter.wasm')).buffer.asUint8List();
_module = await EmscriptenModule.compile(wasmBinaries, 'libspine_flutter');
}
Module? m = _module;