Skip to content

Commit

Permalink
Merge pull request flame-engine#502 from flame-engine/luan.strict-mode
Browse files Browse the repository at this point in the history
Enable strong strict mode on dartalyzer
  • Loading branch information
luanpotter authored Oct 15, 2020
2 parents 2872a73 + 8dd4186 commit a82a789
Show file tree
Hide file tree
Showing 23 changed files with 66 additions and 65 deletions.
5 changes: 5 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/animation_widget/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

void changePosition() async {
await Future.delayed(const Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
setState(() => _position += Vector2.all(10));
}

Expand Down
4 changes: 2 additions & 2 deletions doc/examples/gestures/lib/main_multitap_advanced.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class MyGame extends Game with MultiTouchTapDetector, MultiTouchDragDetector {
_start = position;
}

void onPanUpdate(details) {
void onPanUpdate(DragUpdateDetails details) {
_end = details.localPosition;
}

void onPanEnd(details) {
void onPanEnd(DragEndDetails details) {
_panRect = Rect.fromLTRB(
_start.dx,
_start.dy,
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/isometric/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions doc/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down
8 changes: 4 additions & 4 deletions lib/assets/assets_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/components/parallax_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/components/position_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/effects/combined_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/effects/effects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/effects/move_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/effects/rotate_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/effects/scale_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions lib/effects/sequence_effect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion lib/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 3 additions & 4 deletions lib/game/widget_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -300,7 +299,7 @@ class OverlayWidgetBuilder extends WidgetBuilder {

return OverlayGameWidget(
gameChild: container,
game: game,
game: game as HasWidgetsOverlay,
key: UniqueKey(),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/nine_tile_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions lib/particles/accelerated_particle.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:math';
import 'dart:ui';

import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/sprite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions lib/sprite_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions lib/sprite_batch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand Down Expand Up @@ -77,7 +76,7 @@ class SpriteBatch {
rects,
colors,
blendMode ?? defaultBlendMode,
cullRect ?? defaultCullRect,
cullRect,
paint ?? defaultPaint,
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/spritesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/text_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down

0 comments on commit a82a789

Please sign in to comment.