Skip to content

Commit

Permalink
🏷 Null safety support
Browse files Browse the repository at this point in the history
  • Loading branch information
lig committed Jan 15, 2021
1 parent d39d672 commit 35eb00d
Show file tree
Hide file tree
Showing 124 changed files with 564 additions and 592 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CHANGELOG

## [next]
- Migrate to null safety
- Code improvements and preparing APIs to null-safety
- BaseComponent removes children marked as shouldRemove during update
- Use `find` instead of `globstar` pattern in `scripts/lint.sh` as the later isn't enabled by default in bash
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/animations/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ void main() async {
}

class MyGame extends BaseGame with TapDetector {
Image chopper;
Image creature;
SpriteAnimation animation;
late Image chopper;
late Image creature;
late SpriteAnimation animation;

@override
Future<void> onLoad() async {
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/animations/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-29.10.beta <3.0.0"
flutter: ">=1.24.0-10.2.pre"

dependencies:
flutter:
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/aseprite/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-29.10.beta <3.0.0"
flutter: ">=1.24.0-10.2.pre"

dependencies:
flutter:
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/composability/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ParentSquare extends Square {
}

class MyGame extends BaseGame {
ParentSquare _parent;
late ParentSquare _parent;

@override
bool debugMode = true;
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/composability/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-29.10.beta <3.0.0"
flutter: ">=1.24.0-10.2.pre"

dependencies:
flutter:
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/debug/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() async {

class AndroidComponent extends SpriteComponent {
static const int SPEED = 150;
Vector2 _gameSize;
Vector2? _gameSize;
int xDirection = 1;
int yDirection = 1;

Expand All @@ -39,14 +39,14 @@ class AndroidComponent extends SpriteComponent {
final rect = toRect();

if ((x <= 0 && xDirection == -1) ||
(rect.right >= _gameSize.x && xDirection == 1)) {
(rect.right >= _gameSize!.x && xDirection == 1)) {
xDirection = xDirection * -1;
}

y += yDirection * SPEED * dt;

if ((y <= 0 && yDirection == -1) ||
(rect.bottom >= _gameSize.y && yDirection == 1)) {
(rect.bottom >= _gameSize!.y && yDirection == 1)) {
yDirection = yDirection * -1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/debug/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-29.10.beta <3.0.0"
flutter: ">=1.24.0-10.2.pre"

dependencies:
flutter:
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/effects/combined_effects/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main() async {
}

class MyGame extends BaseGame with TapDetector {
Square greenSquare;
late Square greenSquare;

MyGame() {
final green = Paint()..color = const Color(0xAA338833);
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/effects/combined_effects/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-29.10.beta <3.0.0"
flutter: ">=1.24.0-10.2.pre"

dependencies:
flutter:
Expand Down
8 changes: 4 additions & 4 deletions doc/examples/effects/infinite_effects/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'dart:math';

import 'package:flame/effects/move_effect.dart';
import 'package:flame/effects/scale_effect.dart';
import 'package:flame/effects/rotate_effect.dart';
import 'package:flame/gestures.dart';
import 'package:flame/effects/scale_effect.dart';
import 'package:flame/extensions/vector2.dart';
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
import 'package:flutter/material.dart';

import 'dart:math';

import './square.dart';

void main() async {
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/effects/infinite_effects/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-29.10.beta <3.0.0"
flutter: ">=1.24.0-10.2.pre"

dependencies:
flutter:
Expand Down
12 changes: 6 additions & 6 deletions doc/examples/effects/sequence_effect/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:flame/effects/combined_effect.dart';
import 'package:flame/effects/move_effect.dart';
import 'package:flame/effects/scale_effect.dart';
import 'package:flame/effects/rotate_effect.dart';
import 'package:flame/effects/scale_effect.dart';
import 'package:flame/effects/sequence_effect.dart';
import 'package:flame/gestures.dart';
import 'package:flame/extensions/offset.dart';
import 'package:flame/extensions/vector2.dart';
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
import 'package:flutter/material.dart';

import './square.dart';
Expand All @@ -23,18 +23,18 @@ void main() async {
}

class MyGame extends BaseGame with TapDetector {
Square greenSquare;
Square? greenSquare;

MyGame() {
final green = Paint()..color = const Color(0xAA338833);
greenSquare = Square(green, Vector2.all(100));
add(greenSquare);
add(greenSquare!);
}

@override
void onTapUp(TapUpDetails details) {
final Vector2 currentTap = details.localPosition.toVector2();
greenSquare.clearEffects();
greenSquare!.clearEffects();

final move1 = MoveEffect(
path: [currentTap],
Expand Down Expand Up @@ -85,6 +85,6 @@ class MyGame extends BaseGame with TapDetector {
isAlternating: true,
);
sequence.onComplete = () => print("sequence complete");
greenSquare.addEffect(sequence);
greenSquare!.addEffect(sequence);
}
}
3 changes: 2 additions & 1 deletion doc/examples/effects/sequence_effect/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-29.10.beta <3.0.0"
flutter: ">=1.24.0-10.2.pre"

dependencies:
flutter:
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/effects/simple/lib/main_move.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flame/extensions/offset.dart';
import './square.dart';

class MyGame extends BaseGame with TapDetector {
Square square;
late Square square;

MyGame() {
add(square = Square()
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/effects/simple/lib/main_rotate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flame/effects/effects.dart';
import './square.dart';

class MyGame extends BaseGame with TapDetector {
Square square;
late Square square;

MyGame() {
add(square = Square()
Expand Down
10 changes: 5 additions & 5 deletions doc/examples/effects/simple/lib/main_scale.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
import 'package:flame/anchor.dart';
import 'package:flame/extensions/vector2.dart';
import 'package:flame/effects/effects.dart';
import 'package:flame/extensions/vector2.dart';
import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
import 'package:flutter/material.dart';

import './square.dart';

class MyGame extends BaseGame with TapDetector {
Square square;
late Square square;
bool grow = true;

MyGame() {
Expand Down
3 changes: 2 additions & 1 deletion doc/examples/effects/simple/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0-29.10.beta <3.0.0"
flutter: ">=1.24.0-10.2.pre"

dependencies:
flutter:
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/gestures/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MyGame extends BaseGame
@override
Color backgroundColor() => const Color(0xFFF1F1F1);

Paint _paint;
late Paint _paint;

Rect _rect = const Rect.fromLTWH(50, 50, 50, 50);

Expand Down
4 changes: 2 additions & 2 deletions doc/examples/gestures/lib/main_draggables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DraggableSquare extends PositionComponent with Draggable {
bool debugMode = true;
bool _isDragging = false;

DraggableSquare({Vector2 position}) {
DraggableSquare({Vector2? position}) {
size = Vector2.all(100);
this.position = position ?? Vector2.all(100);
}
Expand All @@ -35,7 +35,7 @@ class DraggableSquare extends PositionComponent with Draggable {
debugColor = _isDragging ? Colors.greenAccent : Colors.purple;
}

Vector2 dragDeltaPosition;
Vector2 dragDeltaPosition = Vector2.zero();
@override
bool onReceiveDrag(DragEvent event) {
event.onUpdate = (DragUpdateDetails details) {
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/gestures/lib/main_mouse_movement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MyGame extends BaseGame with MouseMovementDetector {
static const SPEED = 200;

Vector2 position = Vector2(0, 0);
Vector2 target;
Vector2? target;

final Paint _blue = Paint()..color = const Color(0xFF0000FF);

Expand Down Expand Up @@ -48,10 +48,10 @@ class MyGame extends BaseGame with MouseMovementDetector {
void update(double dt) {
super.update(dt);
if (target != null) {
_onTarget = _toRect().contains(target.toOffset());
_onTarget = _toRect().contains(target!.toOffset());

if (!_onTarget) {
final dir = (target - position).normalized();
final dir = (target! - position).normalized();
position += dir * (SPEED * dt);
}
}
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/gestures/lib/main_multitap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void main() {
class MyGame extends BaseGame with MultiTouchTapDetector {
final _whitePaint = BasicPalette.white.paint;

Paint _paint;
Paint? _paint;

final Map<int, Rect> _taps = {};

Expand Down Expand Up @@ -47,7 +47,7 @@ class MyGame extends BaseGame with MultiTouchTapDetector {
void render(Canvas canvas) {
super.render(canvas);
_taps.values.forEach((rect) {
canvas.drawRect(rect, _paint);
canvas.drawRect(rect, _paint!);
});
}
}
20 changes: 10 additions & 10 deletions doc/examples/gestures/lib/main_multitap_advanced.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class MyGame extends BaseGame
with MultiTouchTapDetector, MultiTouchDragDetector {
final _whitePaint = BasicPalette.white.paint;

Paint _paint;
Paint? _paint;

final Map<int, Rect> _taps = {};

Offset _start;
Offset _end;
Rect _panRect;
Offset? _start;
Offset? _end;
Rect? _panRect;

MyGame() {
_paint = _whitePaint;
Expand Down Expand Up @@ -76,10 +76,10 @@ class MyGame extends BaseGame
void onPanEnd(DragEndDetails details) {
if (_start != null && _end != null) {
_panRect = Rect.fromLTRB(
_start.dx,
_start.dy,
_end.dx,
_end.dy,
_start!.dx,
_start!.dy,
_end!.dx,
_end!.dy,
);
}
}
Expand All @@ -88,11 +88,11 @@ class MyGame extends BaseGame
void render(Canvas canvas) {
super.render(canvas);
_taps.values.forEach((rect) {
canvas.drawRect(rect, _paint);
canvas.drawRect(rect, _paint!);
});

if (_panRect != null) {
canvas.drawRect(_panRect, _paint);
canvas.drawRect(_panRect!, _paint!);
}
}
}
4 changes: 2 additions & 2 deletions doc/examples/gestures/lib/main_overlapping_tapables.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class TapableSquare extends PositionComponent with Tapable {
return PaletteEntry(color).paint;
}

Paint currentPaint;
late Paint currentPaint;

TapableSquare({Vector2 position}) {
TapableSquare({Vector2? position}) {
currentPaint = _randomPaint();
size = Vector2.all(100);
this.position = position ?? Vector2.all(100);
Expand Down
Loading

0 comments on commit 35eb00d

Please sign in to comment.