zero analyzer issues

This commit is contained in:
Renan Araujo
2019-03-23 15:02:17 -03:00
parent aacb3fcb65
commit 6696373bd7
18 changed files with 50 additions and 42 deletions

View File

@ -41,7 +41,7 @@ class _MyHomePageState extends State<MyHomePage> {
void _clickFab(GlobalKey<ScaffoldState> 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<MyHomePage> {
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: <Widget>[
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),
),
);
}

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -122,7 +122,7 @@ class SpriteComponent extends PositionComponent {
}
@override
render(Canvas canvas) {
void render(Canvas canvas) {
prepareCanvas(canvas);
sprite.render(canvas, width, height);
}

View File

@ -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();

View File

@ -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<ParallaxRenderer> _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;
}

View File

@ -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));
}

View File

@ -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;

View File

@ -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;

View File

@ -10,7 +10,7 @@ class TiledComponent extends Component {
String filename;
TileMap map;
Image image;
Map<String, Image> images = Map<String, Image>();
Map<String, Image> images = <String, Image>{};
Future future;
bool _loaded = false;

View File

@ -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;
}
}

View File

@ -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<Component> _addLater = [];
final List<Component> _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<double> _dts = [];
final List<double> _dts = [];
/// This method is called for every component added, both via [add] and [addLater] methods.
///

View File

@ -5,7 +5,7 @@ import 'flame.dart';
import 'position.dart';
class Svg {
DrawableRoot svgRoot = null;
DrawableRoot svgRoot;
Size size;
Svg(String fileName) {