From 6696373bd7dba2af4cd0860021d15f311460b9e1 Mon Sep 17 00:00:00 2001 From: Renan Araujo Date: Sat, 23 Mar 2019 15:02:17 -0300 Subject: [PATCH] zero analyzer issues --- doc/examples/animation_widget/lib/main.dart | 18 +++++++++--------- doc/examples/animations/lib/main.dart | 8 ++++---- doc/examples/aseprite/lib/main.dart | 6 +++--- doc/examples/svg/lib/main.dart | 4 ++-- doc/examples/text/lib/main.dart | 4 ++-- lib/animation.dart | 8 +++++--- lib/box2d/viewport.dart | 3 ++- lib/components/animation_component.dart | 4 ++-- lib/components/component.dart | 2 +- lib/components/composed_component.dart | 2 +- lib/components/parallax_component.dart | 8 ++++---- lib/components/resizable.dart | 2 +- lib/components/text_box_component.dart | 2 ++ lib/components/text_component.dart | 6 +++--- lib/components/tiled_component.dart | 2 +- lib/flame.dart | 3 ++- lib/game.dart | 8 +++++--- lib/svg.dart | 2 +- 18 files changed, 50 insertions(+), 42 deletions(-) diff --git a/doc/examples/animation_widget/lib/main.dart b/doc/examples/animation_widget/lib/main.dart index 48c906f38..1c2f00b55 100644 --- a/doc/examples/animation_widget/lib/main.dart +++ b/doc/examples/animation_widget/lib/main.dart @@ -41,7 +41,7 @@ class _MyHomePageState extends State { void _clickFab(GlobalKey key) { key.currentState.showSnackBar(SnackBar( - content: Text('You clicked the FAB!'), + content: const Text('You clicked the FAB!'), )); } @@ -51,28 +51,28 @@ class _MyHomePageState extends State { return Scaffold( key: key, appBar: AppBar( - title: Text('Animation as a Widget Demo'), + title: const Text('Animation as a Widget Demo'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text('Hi there! This is a regular Flutter app,'), - Text('with a complex widget tree and also'), - Text('some pretty sprite sheet animations :)'), + const Text('Hi there! This is a regular Flutter app,'), + const Text('with a complex widget tree and also'), + const Text('some pretty sprite sheet animations :)'), Flame.util.animationAsWidget( _position, animation.Animation.sequenced('minotaur.png', 19, textureWidth: 96.0)), - Text('Neat, hum?'), - Text('Sprites from Elthen\'s amazing work on itch.io:'), - Text('https://elthen.itch.io/2d-pixel-art-minotaur-sprites'), + const Text('Neat, hum?'), + const Text('Sprites from Elthen\'s amazing work on itch.io:'), + const Text('https://elthen.itch.io/2d-pixel-art-minotaur-sprites'), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () => _clickFab(key), - child: Icon(Icons.add), + child: const Icon(Icons.add), ), ); } diff --git a/doc/examples/animations/lib/main.dart b/doc/examples/animations/lib/main.dart index ab5d27acc..924d0b1f1 100644 --- a/doc/examples/animations/lib/main.dart +++ b/doc/examples/animations/lib/main.dart @@ -1,6 +1,6 @@ import 'package:flame/flame.dart'; import 'package:flame/game.dart'; -import 'package:flame/animation.dart' as FlameAnimation; +import 'package:flame/animation.dart' as flame_animation; import 'package:flame/components/animation_component.dart'; import 'package:flutter/material.dart'; @@ -11,10 +11,10 @@ class MyGame extends BaseGame { _start(); } - _start() async { - Size size = await Flame.util.initialDimensions(); + void _start() async { + final Size size = await Flame.util.initialDimensions(); - final animation = await FlameAnimation.Animation.sequenced('chopper.png', 4, + final animation = flame_animation.Animation.sequenced('chopper.png', 4, textureWidth: 48, textureHeight: 48, stepTime: 0.15); final animationComponent = AnimationComponent(100, 100, animation); diff --git a/doc/examples/aseprite/lib/main.dart b/doc/examples/aseprite/lib/main.dart index c24a9e85e..a47b90f03 100644 --- a/doc/examples/aseprite/lib/main.dart +++ b/doc/examples/aseprite/lib/main.dart @@ -1,6 +1,6 @@ import 'package:flame/flame.dart'; import 'package:flame/game.dart'; -import 'package:flame/animation.dart' as FlameAnimation; +import 'package:flame/animation.dart' as flame_animation; import 'package:flame/components/animation_component.dart'; import 'package:flutter/material.dart'; @@ -11,10 +11,10 @@ class MyGame extends BaseGame { _start(); } - _start() async { + void _start() async { final Size size = await Flame.util.initialDimensions(); - final animation = await FlameAnimation.Animation.fromAsepriteData( + final animation = await flame_animation.Animation.fromAsepriteData( 'chopper.png', 'chopper.json'); final animationComponent = AnimationComponent(200, 200, animation); diff --git a/doc/examples/svg/lib/main.dart b/doc/examples/svg/lib/main.dart index 73bdd4405..b2fccb4ac 100644 --- a/doc/examples/svg/lib/main.dart +++ b/doc/examples/svg/lib/main.dart @@ -5,7 +5,7 @@ import 'package:flame/components/component.dart' show SvgComponent; import 'package:flutter/material.dart'; -void main() => runApp(MyGame()); +void main() => runApp(MyGame().widget); class MyGame extends BaseGame { Svg svgInstance; @@ -15,7 +15,7 @@ class MyGame extends BaseGame { _start(); } - _start() async { + void _start() { svgInstance = Svg('android.svg'); android = SvgComponent.fromSvg(100, 100, svgInstance); android.x = 100; diff --git a/doc/examples/text/lib/main.dart b/doc/examples/text/lib/main.dart index d3e534313..e16ec333c 100644 --- a/doc/examples/text/lib/main.dart +++ b/doc/examples/text/lib/main.dart @@ -16,7 +16,7 @@ TextConfig tiny = regular.withFontSize(12.0); class MyTextBox extends TextBoxComponent { MyTextBox(String text) - : super(text, config: tiny, boxConfig: TextBoxConfig(timePerChar: 0.05)); + : super(text, config: tiny, boxConfig: const TextBoxConfig(timePerChar: 0.05)); @override void drawBackground(Canvas c) { @@ -35,7 +35,7 @@ class MyGame extends BaseGame { _start(); } - _start() async { + void _start() async { final Size size = await Flame.util.initialDimensions(); add(TextComponent('Hello, Flame', config: regular) diff --git a/lib/animation.dart b/lib/animation.dart index 94458ca01..63f725256 100644 --- a/lib/animation.dart +++ b/lib/animation.dart @@ -34,6 +34,9 @@ class Animation { /// Whether the animation loops after the last sprite of the list, going back to the first, or keeps returning the last when done. bool loop = true; + /// Creates an animation given a list of frames. + Animation(this.frames, {this.loop = true}); + /// Creates an empty animation Animation.empty(); @@ -46,8 +49,7 @@ class Animation { frames = sprites.map((s) => Frame(s, stepTime)).toList(); } - /// Creates an animation given a list of frames. - Animation(this.frames, {this.loop = true}); + /// Automatically creates a sequenced animation, that is, an animation based on a sprite sheet. /// @@ -156,7 +158,7 @@ class Animation { } /// Sets a fixed step time to all frames. - void set stepTime(double stepTime) { + set stepTime(double stepTime) { frames.forEach((frame) => frame.stepTime = stepTime); } diff --git a/lib/box2d/viewport.dart b/lib/box2d/viewport.dart index 03716fc00..223690bb5 100644 --- a/lib/box2d/viewport.dart +++ b/lib/box2d/viewport.dart @@ -6,6 +6,7 @@ import 'package:flame/box2d/box2d_component.dart'; class Viewport extends ViewportTransform { Size size; + @override double scale; Viewport(this.size, this.scale) @@ -36,7 +37,7 @@ class Viewport extends ViewportTransform { /// /// @param screens multiplies the visible screen with to create a bigger virtual screen. /// @return the percentage in the range of [0, 1] - double getCenterHorizontalScreenPercentage({double screens: 1.0}) { + double getCenterHorizontalScreenPercentage({double screens = 1.0}) { final width = size.width * screens; final x = center.x + ((screens - 1) * size.width / 2); final double rest = x.abs() % width; diff --git a/lib/components/animation_component.dart b/lib/components/animation_component.dart index b4301a5ce..c189b2a7a 100644 --- a/lib/components/animation_component.dart +++ b/lib/components/animation_component.dart @@ -20,8 +20,8 @@ class AnimationComponent extends PositionComponent { int amount, { double textureX = 0.0, double textureY = 0.0, - double textureWidth = null, - double textureHeight = null, + double textureWidth, + double textureHeight, }) { this.width = width; this.height = height; diff --git a/lib/components/component.dart b/lib/components/component.dart index a8ca9bc5e..fb565b549 100644 --- a/lib/components/component.dart +++ b/lib/components/component.dart @@ -122,7 +122,7 @@ class SpriteComponent extends PositionComponent { } @override - render(Canvas canvas) { + void render(Canvas canvas) { prepareCanvas(canvas); sprite.render(canvas, width, height); } diff --git a/lib/components/composed_component.dart b/lib/components/composed_component.dart index 0e0f94427..e1121cabf 100644 --- a/lib/components/composed_component.dart +++ b/lib/components/composed_component.dart @@ -37,7 +37,7 @@ mixin ComposedComponent on Component { OrderedSet(Comparing.on((c) => c.priority())); @override - render(Canvas canvas) { + void render(Canvas canvas) { canvas.save(); components.forEach((comp) => _renderComponent(canvas, comp)); canvas.restore(); diff --git a/lib/components/parallax_component.dart b/lib/components/parallax_component.dart index a4ef4ffca..8b896a15e 100644 --- a/lib/components/parallax_component.dart +++ b/lib/components/parallax_component.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:ui'; -import 'package:flutter/src/painting/decoration_image.dart'; +import 'package:flutter/painting.dart'; import '../flame.dart'; import 'component.dart'; @@ -48,8 +48,8 @@ class ParallaxRenderer { } abstract class ParallaxComponent extends PositionComponent { - final BASE_SPEED = 30; - final LAYER_DELTA = 40; + final baseSpeed = 30; + final layerDelta = 40; final List _layers = []; Size _size; @@ -108,7 +108,7 @@ abstract class ParallaxComponent extends PositionComponent { } for (int i = 0; i < _layers.length; i++) { double scroll = _layers[i].scroll; - scroll += (BASE_SPEED + i * LAYER_DELTA) * delta / _size.width; + scroll += (baseSpeed + i * layerDelta) * delta / _size.width; if (scroll > 1) { scroll = scroll % 1; } diff --git a/lib/components/resizable.dart b/lib/components/resizable.dart index 470176d93..a9f3634d5 100644 --- a/lib/components/resizable.dart +++ b/lib/components/resizable.dart @@ -9,7 +9,7 @@ class Resizable { Size size; /// Implementation provided by this mixin to the resize hook. - resize(Size size) { + void resize(Size size) { this.size = size; children().where((e) => e != null).forEach((e) => e.resize(size)); } diff --git a/lib/components/text_box_component.dart b/lib/components/text_box_component.dart index 5633d80ed..e75daac5b 100644 --- a/lib/components/text_box_component.dart +++ b/lib/components/text_box_component.dart @@ -126,6 +126,7 @@ class TextBoxComponent extends PositionComponent with Resizable { double get currentHeight => _withMargins((currentLine + 1) * _lineHeight); + @override void render(Canvas c) { if (_cache == null) { return; @@ -168,6 +169,7 @@ class TextBoxComponent extends PositionComponent with Resizable { _cache = await _redrawCache(); } + @override void update(double dt) { final int prevCurrentChar = currentChar; _lifeTime += dt; diff --git a/lib/components/text_component.dart b/lib/components/text_component.dart index 62f34f98e..80eef9dab 100644 --- a/lib/components/text_component.dart +++ b/lib/components/text_component.dart @@ -1,6 +1,6 @@ import 'dart:ui'; -import 'package:flutter/src/painting/text_painter.dart'; +import 'package:flutter/painting.dart'; import 'component.dart'; import '../position.dart'; @@ -10,14 +10,14 @@ class TextComponent extends PositionComponent { String _text; TextConfig _config; - get text => _text; + String get text => _text; set text(String text) { _text = text; _updateBox(); } - get config => _config; + TextConfig get config => _config; set config(TextConfig config) { _config = config; diff --git a/lib/components/tiled_component.dart b/lib/components/tiled_component.dart index e9f574f42..265b232e2 100644 --- a/lib/components/tiled_component.dart +++ b/lib/components/tiled_component.dart @@ -10,7 +10,7 @@ class TiledComponent extends Component { String filename; TileMap map; Image image; - Map images = Map(); + Map images = {}; Future future; bool _loaded = false; diff --git a/lib/flame.dart b/lib/flame.dart index 15b1eaec7..9be824656 100644 --- a/lib/flame.dart +++ b/lib/flame.dart @@ -62,7 +62,8 @@ class FlameBiding extends BindingBase with GestureBinding, ServicesBinding { static FlameBiding instance; static FlameBiding ensureInitialized() { - if (FlameBiding.instance == null) FlameBiding(); + if (FlameBiding.instance == null) + FlameBiding(); return FlameBiding.instance; } } diff --git a/lib/game.dart b/lib/game.dart index 3756cc15a..98a4f2c46 100644 --- a/lib/game.dart +++ b/lib/game.dart @@ -112,7 +112,9 @@ class _GameRenderBox extends RenderBox with WidgetsBindingObserver { } void _tick(Duration timestamp) { - if (!attached) return; + if (!attached) { + return; + } _scheduleTick(); _update(timestamp); markNeedsPaint(); @@ -166,7 +168,7 @@ abstract class BaseGame extends Game { OrderedSet(Comparing.on((c) => c.priority())); /// Components added by the [addLater] method - List _addLater = []; + final List _addLater = []; /// Current screen size, updated every resize via the [resize] method hook Size size; @@ -175,7 +177,7 @@ abstract class BaseGame extends Game { Position camera = Position.empty(); /// List of deltas used in debug mode to calculate FPS - List _dts = []; + final List _dts = []; /// This method is called for every component added, both via [add] and [addLater] methods. /// diff --git a/lib/svg.dart b/lib/svg.dart index d11fad4e8..fbaf28924 100644 --- a/lib/svg.dart +++ b/lib/svg.dart @@ -5,7 +5,7 @@ import 'flame.dart'; import 'position.dart'; class Svg { - DrawableRoot svgRoot = null; + DrawableRoot svgRoot; Size size; Svg(String fileName) {