mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
Linting
This commit is contained in:
@ -87,24 +87,23 @@ void main() async {
|
|||||||
rows: 1,
|
rows: 1,
|
||||||
);
|
);
|
||||||
final _animation = _animationSpriteSheet.createAnimation(
|
final _animation = _animationSpriteSheet.createAnimation(
|
||||||
0,
|
0,
|
||||||
stepTime: 0.2,
|
stepTime: 0.2,
|
||||||
to: 3,
|
to: 3,
|
||||||
loop: true,
|
loop: true,
|
||||||
);
|
);
|
||||||
dashbook.storiesOf('FlameAnimationWidget').decorator(CenterDecorator())
|
dashbook.storiesOf('FlameAnimationWidget').decorator(CenterDecorator()).add(
|
||||||
.add(
|
'default',
|
||||||
'default',
|
(ctx) => Container(
|
||||||
(ctx) => Container(
|
width: ctx.numberProperty('container width', 400),
|
||||||
width: ctx.numberProperty('container width', 400),
|
height: ctx.numberProperty('container height', 200),
|
||||||
height: ctx.numberProperty('container height', 200),
|
padding: const EdgeInsets.all(20),
|
||||||
padding: const EdgeInsets.all(20),
|
child: FlameAnimationWidget(
|
||||||
child: FlameAnimationWidget(
|
animation: _animation,
|
||||||
animation: _animation,
|
play: ctx.boolProperty('playing', true),
|
||||||
play: ctx.boolProperty('playing', true),
|
center: ctx.boolProperty('center', true),
|
||||||
center: ctx.boolProperty('center', true),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
runApp(dashbook);
|
runApp(dashbook);
|
||||||
|
|||||||
@ -14,14 +14,14 @@ class FlameAnimationWidget extends StatefulWidget {
|
|||||||
this.animation,
|
this.animation,
|
||||||
this.play = true,
|
this.play = true,
|
||||||
this.center = false,
|
this.center = false,
|
||||||
}): assert(animation.loaded(), 'Animation must be loaded');
|
}) : assert(animation.loaded(), 'Animation must be loaded');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State createState() => _FlameAnimationWidget();
|
State createState() => _FlameAnimationWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FlameAnimationWidget extends State<FlameAnimationWidget> with SingleTickerProviderStateMixin {
|
class _FlameAnimationWidget extends State<FlameAnimationWidget>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
AnimationController _controller;
|
AnimationController _controller;
|
||||||
int _lastUpdated;
|
int _lastUpdated;
|
||||||
|
|
||||||
@ -39,19 +39,17 @@ class _FlameAnimationWidget extends State<FlameAnimationWidget> with SingleTicke
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_controller = AnimationController(
|
_controller = AnimationController(vsync: this)
|
||||||
vsync: this
|
..addListener(() {
|
||||||
)
|
final now = DateTime.now().millisecond;
|
||||||
..addListener(() {
|
|
||||||
final now = DateTime.now().millisecond;
|
|
||||||
|
|
||||||
final dt = max(0, (now - _lastUpdated) / 1000);
|
final dt = max(0, (now - _lastUpdated) / 1000);
|
||||||
widget.animation.update(dt);
|
widget.animation.update(dt);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_lastUpdated = now;
|
_lastUpdated = now;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
widget.animation.onCompleteAnimation = _pauseAnimation;
|
widget.animation.onCompleteAnimation = _pauseAnimation;
|
||||||
|
|
||||||
@ -66,8 +64,7 @@ class _FlameAnimationWidget extends State<FlameAnimationWidget> with SingleTicke
|
|||||||
_lastUpdated = DateTime.now().millisecond;
|
_lastUpdated = DateTime.now().millisecond;
|
||||||
_controller.repeat(
|
_controller.repeat(
|
||||||
// -/+ 60 fps
|
// -/+ 60 fps
|
||||||
period: Duration(milliseconds: 16)
|
period: Duration(milliseconds: 16));
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +82,7 @@ class _FlameAnimationWidget extends State<FlameAnimationWidget> with SingleTicke
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(ctx) {
|
Widget build(ctx) {
|
||||||
return FlameSpriteWidget(sprite: widget.animation.getSprite(), center: widget.center);
|
return FlameSpriteWidget(
|
||||||
|
sprite: widget.animation.getSprite(), center: widget.center);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,8 @@ class _FlameSpritePainer extends CustomPainter {
|
|||||||
_FlameSpritePainer(this._sprite, this._center);
|
_FlameSpritePainer(this._sprite, this._center);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRepaint(_FlameSpritePainer old) => old._sprite != _sprite || old._center != _center;
|
bool shouldRepaint(_FlameSpritePainer old) =>
|
||||||
|
old._sprite != _sprite || old._center != _center;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
|
|||||||
Reference in New Issue
Block a user