Enable strong strict mode on dartalyzer

This commit is contained in:
Luan Nico
2020-10-14 22:36:14 -04:00
parent 91a2873edc
commit b4b20655e0
21 changed files with 63 additions and 62 deletions

View File

@ -1,6 +1,11 @@
# Source of linter options:
# http://dart-lang.github.io/linter/lints/options/options.html
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
linter:
rules:
- always_declare_return_types

View File

@ -12,7 +12,7 @@ import 'dart:ui';
const x = 500.0;
const y = 500.0;
const s = 64;
const s = 64.0;
final topLeft = Vector2(x, y);
void main() async {
@ -64,12 +64,12 @@ class MyGame extends BaseGame with MouseMovementDetector {
base = IsometricTileMapComponent(
tileset,
matrix,
destTileSize: Vector2.all(s.toDouble()),
destTileSize: Vector2.all(s),
)
..x = x
..y = y,
);
add(selector = Selector(s.toDouble(), selectorImage));
add(selector = Selector(s, selectorImage));
}
@override

View File

@ -214,10 +214,9 @@ This constructor makes creating an Animation very easy using sprite sheets.
If you use Aseprite for your animations, Flame does provide some support for Aseprite animation's JSON data. To use this feature you will need to export the Sprite Sheet's JSON data, and use something like the following snippet:
```dart
SpriteAnimation animation = await Animation.fromAsepriteData(
imageInstance, // Sprite Sheet image path
"./assets/chopper.json" // Sprite Sheet animation JSON data
);
final image = await images.load('chopper.png');
final jsonData = await assets.readJson('chopper.json');
final animation = SpriteAnimation.fromAsepriteData(image, jsonData);
```
_Note: trimmed sprite sheets are not supported by flame, so if you export your sprite sheet this way, it will have the trimmed size, not the sprite original size._

View File

@ -30,7 +30,7 @@ class AssetsCache {
'"$fileName" is not a String Asset',
);
return _files[fileName].value;
return _files[fileName].value as String;
}
/// Reads a binary file from assets folder
@ -44,12 +44,12 @@ class AssetsCache {
'"$fileName" is not a Binary Asset',
);
return _files[fileName].value;
return _files[fileName].value as List<int>;
}
Future<Map<String, dynamic>> readJson(String fileName) async {
final String content = await readFile(fileName);
return jsonDecode(content);
return jsonDecode(content) as Map<String, dynamic>;
}
Future<_StringAsset> _readFile(String fileName) async {
@ -61,7 +61,7 @@ class AssetsCache {
final data = await rootBundle.load('assets/$fileName');
final Uint8List list = Uint8List.view(data.buffer);
final bytes = List.from(list).cast<int>();
final bytes = List<int>.from(list);
return _BinaryAsset()..value = bytes;
}
}

View File

@ -74,7 +74,7 @@ class ParallaxLayer {
// The image size so that it fulfills the LayerFill parameter
_imageSize =
Vector2(_image.width.toDouble(), _image.height.toDouble()) / _scale;
Vector2Extension.fromInts(_image.width, _image.height) / _scale;
// Number of images that can fit on the canvas plus one
// to have something to scroll to without leaving canvas empty
@ -138,7 +138,7 @@ class ParallaxLayer {
);
}
Future<Image> _load(filename) {
Future<Image> _load(String filename) {
return Flame.images.load(filename).then((image) {
_image = image;
if (_screenSize != null) {

View File

@ -202,8 +202,8 @@ abstract class PositionComponent extends Component {
return _children.remove(c);
}
Iterable<PositionComponent> removeChildren(
bool Function(PositionComponent) test,
Iterable<Component> removeChildren(
bool Function(Component) test,
) {
return _children.removeWhere(test);
}

View File

@ -14,7 +14,7 @@ class CombinedEffect extends PositionComponentEffect {
this.offset = 0.0,
bool isInfinite = false,
bool isAlternating = false,
Function onComplete,
void Function() onComplete,
}) : super(isInfinite, isAlternating, onComplete: onComplete) {
assert(
effects.every((effect) => effect.component == null),
@ -75,7 +75,7 @@ class CombinedEffect extends PositionComponentEffect {
effects.forEach((effect) => effect.dispose());
}
void _updateEffect(final effect, double dt) {
void _updateEffect(PositionComponentEffect effect, double dt) {
final isReverse = curveDirection.isNegative;
final initialOffset = effects.indexOf(effect) * offset;
final effectOffset = isReverse

View File

@ -117,10 +117,10 @@ abstract class PositionComponentEffect
Vector2 endSize;
PositionComponentEffect(
initialIsInfinite,
initialIsAlternating, {
isRelative = false,
onComplete,
bool initialIsInfinite,
bool initialIsAlternating, {
bool isRelative = false,
void Function() onComplete,
}) : super(
initialIsInfinite,
initialIsAlternating,

View File

@ -30,10 +30,10 @@ class MoveEffect extends PositionComponentEffect {
@required this.path,
@required this.speed,
this.curve,
isInfinite = false,
isAlternating = false,
isRelative = false,
Function onComplete,
bool isInfinite = false,
bool isAlternating = false,
bool isRelative = false,
void Function() onComplete,
}) : super(
isInfinite,
isAlternating,

View File

@ -14,10 +14,10 @@ class RotateEffect extends PositionComponentEffect {
@required this.radians, // As many radians as you want to rotate
@required this.speed, // In radians per second
this.curve,
isInfinite = false,
isAlternating = false,
isRelative = false,
Function onComplete,
bool isInfinite = false,
bool isAlternating = false,
bool isRelative = false,
void Function() onComplete,
}) : super(
isInfinite,
isAlternating,

View File

@ -15,10 +15,10 @@ class ScaleEffect extends PositionComponentEffect {
@required this.size,
@required this.speed,
this.curve,
isInfinite = false,
isAlternating = false,
isRelative = false,
Function onComplete,
bool isInfinite = false,
bool isAlternating = false,
bool isRelative = false,
void Function() onComplete,
}) : super(
isInfinite,
isAlternating,

View File

@ -12,9 +12,9 @@ class SequenceEffect extends PositionComponentEffect {
SequenceEffect({
@required this.effects,
isInfinite = false,
isAlternating = false,
Function onComplete,
bool isInfinite = false,
bool isAlternating = false,
void Function() onComplete,
}) : super(isInfinite, isAlternating, onComplete: onComplete) {
assert(
effects.every((effect) => effect.component == null),

View File

@ -55,7 +55,7 @@ abstract class Game {
/// You can add it directly to the runApp method or inside your widget structure (if you use vanilla screens and widgets).
Widget get widget => builder.build(this);
void _handleKeyEvent(e) {
void _handleKeyEvent(RawKeyEvent e) {
(this as KeyboardEvents).onKeyEvent(e);
}

View File

@ -33,8 +33,7 @@ class _GenericTapEventHandler {
}
Widget _applyAdvancedGesturesDetectors(Game game, Widget child) {
final Map<Type, GestureRecognizerFactory> gestures =
<Type, GestureRecognizerFactory>{};
final Map<Type, GestureRecognizerFactory> gestures = {};
final List<_GenericTapEventHandler> _tapHandlers = [];
@ -207,7 +206,7 @@ Widget _applyBasicGesturesDetectors(Game game, Widget child) {
);
}
Widget _applyMouseDetectors(game, Widget child) {
Widget _applyMouseDetectors(Game game, Widget child) {
return MouseRegion(
child: Listener(
child: child,
@ -300,7 +299,7 @@ class OverlayWidgetBuilder extends WidgetBuilder {
return OverlayGameWidget(
gameChild: container,
game: game,
game: game as HasWidgetsOverlay,
key: UniqueKey(),
);
}

View File

@ -55,14 +55,14 @@ class NineTileBox {
// horizontal sides
final mx = size.x - 2 * destTileSize;
final middleLeft = position + Vector2(destTileSize.toDouble(), 0);
final middleLeft = position + Vector2Extension.fromInts(destTileSize, 0);
_drawTile(c, _getDest(middleLeft, width: mx), 1, 0);
final middleRight = middleLeft + Vector2(0, size.y - destTileSize);
_drawTile(c, _getDest(middleRight, width: mx), 1, 2);
// vertical sides
final my = size.y - 2 * destTileSize;
final topCenter = position + Vector2(0, destTileSize.toDouble());
final topCenter = position + Vector2Extension.fromInts(0, destTileSize);
_drawTile(c, _getDest(topCenter, height: my), 0, 1);
final bottomCenter = topCenter + Vector2(size.x - destTileSize, 0);
_drawTile(c, _getDest(bottomCenter, height: my), 2, 1);

View File

@ -1,4 +1,3 @@
import 'dart:math';
import 'dart:ui';
import 'package:flutter/foundation.dart';
@ -41,7 +40,7 @@ class AcceleratedParticle extends CurvedParticle with SingleChildParticle {
@override
void update(double t) {
speed += acceleration * t;
position += speed * t - (acceleration * pow(t, 2)) / 2;
position += speed * t - (acceleration * t * t) / 2;
super.update(t);
}

View File

@ -27,7 +27,7 @@ class Sprite {
Vector2 get srcSize => Vector2(src.width, src.height);
set srcSize(Vector2 size) {
size ??= Vector2(image.width.toDouble(), image.height.toDouble());
size ??= Vector2Extension.fromInts(image.width, image.height);
src = (srcPosition ?? Vector2.zero()).toPositionedRect(size);
}

View File

@ -127,16 +127,16 @@ class SpriteAnimation {
Image image,
Map<String, dynamic> jsonData,
) {
final Map<String, dynamic> jsonFrames = jsonData['frames'];
final jsonFrames = jsonData['frames'] as Map<String, Map<String, dynamic>>;
final frames = jsonFrames.values.map((value) {
final frameData = value['frame'];
final int x = frameData['x'];
final int y = frameData['y'];
final int width = frameData['w'];
final int height = frameData['h'];
final frameData = value['frame'] as Map<String, dynamic>;
final int x = frameData['x'] as int;
final int y = frameData['y'] as int;
final int width = frameData['w'] as int;
final int height = frameData['h'] as int;
final stepTime = value['duration'] / 1000;
final stepTime = (value['duration'] as int) / 1000;
final Sprite sprite = Sprite(
image,

View File

@ -13,10 +13,9 @@ class SpriteBatch {
List<Color> colors = [];
static const defaultBlendMode = BlendMode.srcOver;
static const defaultCullRect = null;
static const defaultColor = const Color(0x00000000); // transparent
static final defaultPaint = Paint();
static final defaultTransform = RSTransform(1, 0, 0, 0);
static const defaultColor = const Color(0x00000000); // transparent
SpriteBatch(this.atlas);
@ -28,7 +27,7 @@ class SpriteBatch {
int get height => atlas.height;
Vector2 get size => Vector2(width.toDouble(), height.toDouble());
Vector2 get size => Vector2Extension.fromInts(width, height);
void addTransform({
@required Rect rect,
@ -77,7 +76,7 @@ class SpriteBatch {
rects,
colors,
blendMode ?? defaultBlendMode,
cullRect ?? defaultCullRect,
cullRect,
paint ?? defaultPaint,
);
}

View File

@ -69,11 +69,11 @@ class SpriteSheet {
}
Sprite _computeSprite(int spriteId) {
final i = (spriteId % columns).toDouble();
final j = (spriteId ~/ columns).toDouble();
final i = spriteId % columns;
final j = spriteId ~/ columns;
return Sprite(
image,
srcPosition: Vector2(i, j)..multiply(srcSize),
srcPosition: Vector2Extension.fromInts(i, j)..multiply(srcSize),
srcSize: srcSize,
);
}

View File

@ -55,8 +55,8 @@ class TextConfig {
/// For proper fonts of languages like Hebrew or Arabic, replace this with [TextDirection.rtl].
final TextDirection textDirection;
final MemoryCache _textPainterCache =
MemoryCache<String, material.TextPainter>();
final MemoryCache<String, material.TextPainter> _textPainterCache =
MemoryCache();
/// Creates a constant [TextConfig] with sensible defaults.
///