Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Solve warnings from 3.10.0 analyzer #2532

Merged
merged 10 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AnimationGroupExample extends FlameGame with TapDetector {
back to the original animation.
''';

late SpriteAnimationGroupComponent robot;
late SpriteAnimationGroupComponent<RobotState> robot;

@override
Future<void> onLoad() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SimpleIsolateExample extends FlameGame {
''';

@override
Future onLoad() async {
Future<void> onLoad() async {
camera.viewport = FixedResolutionViewport(Vector2(400, 600));

const rect = Rect.fromLTRB(80, 230, 320, 470);
Expand Down Expand Up @@ -86,7 +86,7 @@ class CalculatePrimeNumber extends PositionComponent
}

@override
Future onMount() {
Future<void> onMount() {
_interval = Timer(0.4, repeat: true, onTick: _checkNextAgainstPrime)
..start();
return super.onMount();
Expand All @@ -113,7 +113,7 @@ class CalculatePrimeNumber extends PositionComponent
_isPrime(_primeStartNumber),
);

Future _checkNextAgainstPrime() async {
Future<void> _checkNextAgainstPrime() async {
final nextInt = _primeData.key + 1;

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/lib/src/cache/assets_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:flutter/services.dart' show rootBundle;
/// It automatically looks for files in the `assets` directory.
class AssetsCache {
final String prefix;
final Map<String, _Asset> _files = {};
final Map<String, _Asset<dynamic>> _files = {};

AssetsCache({this.prefix = 'assets/'});

Expand Down
19 changes: 13 additions & 6 deletions packages/flame/lib/src/components/text_box_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TextBoxComponent<T extends TextRenderer> extends TextComponent {
static final Paint _imagePaint = BasicPalette.white.paint()
..filterQuality = FilterQuality.high;
final TextBoxConfig _boxConfig;
final double pixelRatio;
double? pixelRatio;

@visibleForTesting
final List<String> lines = [];
Expand Down Expand Up @@ -81,7 +81,8 @@ class TextBoxComponent<T extends TextRenderer> extends TextComponent {
}) : _boxConfig = boxConfig ?? TextBoxConfig(),
_fixedSize = size != null,
align = align ?? Anchor.topLeft,
pixelRatio = pixelRatio ?? window.devicePixelRatio;
pixelRatio = pixelRatio ??
PlatformDispatcher.instance.views.first.devicePixelRatio;

/// Alignment of the text within its bounding box.
///
Expand Down Expand Up @@ -125,6 +126,12 @@ class TextBoxComponent<T extends TextRenderer> extends TextComponent {
if (cache == null) {
redraw();
}
final game = findGame();
final context = game?.buildContext;
if (pixelRatio == null && game != null && context != null) {
pixelRatio = View.of(context).devicePixelRatio;
}
pixelRatio ??= 1.0;
}

@override
Expand Down Expand Up @@ -233,19 +240,19 @@ class TextBoxComponent<T extends TextRenderer> extends TextComponent {
return;
}
canvas.save();
canvas.scale(1 / pixelRatio);
canvas.scale(1 / pixelRatio!);
canvas.drawImage(cache!, Offset.zero, _imagePaint);
canvas.restore();
}

Future<Image> _fullRenderAsImage(Vector2 size) {
final recorder = PictureRecorder();
final c = Canvas(recorder, size.toRect());
c.scale(pixelRatio);
c.scale(pixelRatio!);
_fullRender(c);
return recorder.endRecording().toImageSafe(
(width * pixelRatio).ceil(),
(height * pixelRatio).ceil(),
(width * pixelRatio!).ceil(),
(height * pixelRatio!).ceil(),
);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/flame/test/collisions/collision_test_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class CollisionDetectionWorld extends World with HasCollisionDetection {}
@isTest
Future<void> testCollisionDetectionGame(
String testName,
Future Function(HasCollidablesGame) testBody,
Future<void> Function(HasCollidablesGame) testBody,
) {
return testWithGame(testName, HasCollidablesGame.new, testBody);
}

@isTest
Future<void> testQuadTreeCollisionDetectionGame(
String testName,
Future Function(HasCollisionDetection) testBody,
Future<void> Function(HasCollisionDetection) testBody,
) {
return testWithGame(
testName,
Expand All @@ -39,7 +39,7 @@ Future<void> testQuadTreeCollisionDetectionGame(
}

Future<void> runCollisionTestRegistry(
Map<String, Future Function(HasCollisionDetection)> testRegistry,
Map<String, Future<void> Function(HasCollisionDetection)> testRegistry,
) async {
for (final entry in testRegistry.entries) {
final name = entry.key;
Expand Down
6 changes: 3 additions & 3 deletions packages/flame_bloc/example/lib/src/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class GameView extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Column(
return const Column(
children: [
const GameStat(),
GameStat(),
Expanded(
child: Stack(
children: const [
children: [
Positioned.fill(child: Game()),
Positioned(top: 50, right: 10, child: Inventory()),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class WorkerOvermind extends Component
late WorkerOvermindHud isolateHud;

@override
Future onLoad() async {
Future<void> onLoad() async {
gameRef.add(isolateHud = WorkerOvermindHud());
super.onLoad();
}

@override
Future onMount() {
Future<void> onMount() {
calculateTasks();
_assignTaskInterval = Timer(0.2, repeat: true, onTick: _assignTasks)
..start();
Expand Down Expand Up @@ -57,7 +57,7 @@ class WorkerOvermind extends Component
/// Function that pairs a job and a worker.
///
/// Using an isolate for the actual calculation.
Future _assignTasks() async {
Future<void> _assignTasks() async {
if (_queuedTasks.isEmpty) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_isolate/example/lib/colonists_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ColonistsGame extends FlameGame with KeyboardEvents {
late final WorkerOvermind workerOvermind;

@override
Future onLoad() async {
Future<void> onLoad() async {
await Flame.images.load('bread.png');
await Flame.images.load('worker.png');
await Flame.images.load('cheese.png');
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_isolate/example/lib/game_map/game_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GameMap extends Component with HasGameRef<ColonistsGame> {
static const double workerMaxSpeed = 75;

@override
Future onLoad() async {
Future<void> onLoad() async {
for (var x = 0; x < mapSizeX; x++) {
for (var y = 0; y < mapSizeY; y++) {
addTerrain(IntVector2(x, y), Grass());
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_isolate/lib/flame_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mixin FlameIsolate on Component implements IsolateGetter {
BackpressureStrategy get backpressureStrategy => NoBackPressureStrategy();

@override
Future onMount() async {
Future<void> onMount() async {
_isolate = Isolated(backpressureStrategy: backpressureStrategy);
_isolate?.init();
return super.onMount();
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_jenny/jenny/lib/src/command_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class ArgumentsLexer {
List<String> tokenize() {
pushMode(modeStartOfArgument);
while (!eof) {
final ok = (modeStack.last)();
final ok = modeStack.last();
assert(ok);
}
if (modeStack.last == modeTextArgument) {
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_jenny/jenny/lib/src/parse/tokenize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _Lexer {
indentStack.add(0);
pushMode(modeMain);
while (!eof) {
final ok = (modeStack.last)();
final ok = modeStack.last();
if (!ok) {
error('invalid token');
}
Expand Down
6 changes: 3 additions & 3 deletions packages/flame_lint/lib/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# https://dart-lang.github.io/linter/lints/options/options.html

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
exclude:
- "**/*.g.dart"
language:
strict-casts: true
strict-raw-types: false

linter:
rules:
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_studio/lib/src/core/game_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _GameController extends StateNotifier<_GameState> {
}
}

WidgetsBinding.instance.renderViewElement?.visitChildElements(visitor);
WidgetsBinding.instance.rootElement?.visitChildElements(visitor);
return game;
}
}
3 changes: 2 additions & 1 deletion packages/flame_studio/lib/src/widgets/left_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class LeftPanel extends ConsumerWidget {

return Directionality(
textDirection: ref.watch(textDirectionProvider),
child: MediaQuery.fromWindow(
child: MediaQuery.fromView(
view: View.of(context),
child: Container(
constraints: BoxConstraints.tightFor(width: width),
decoration: BoxDecoration(
Expand Down
3 changes: 2 additions & 1 deletion packages/flame_svg/lib/svg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Svg {
/// Creates an [Svg] with the received [pictureInfo].
/// Default [pixelRatio] is the device pixel ratio.
Svg(this.pictureInfo, {double? pixelRatio})
: pixelRatio = pixelRatio ?? window.devicePixelRatio;
: pixelRatio = pixelRatio ??
PlatformDispatcher.instance.views.first.devicePixelRatio;

final MemoryCache<Size, Image> _imageCache = MemoryCache();

Expand Down
2 changes: 1 addition & 1 deletion packages/flame_svg/test/svg_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void main() {
final flameSvg = await parseSvgFromTestFile('test/_resources/hand.svg');
flameSvg.render(Canvas(PictureRecorder()), Vector2.all(300));
await tester.binding.setSurfaceSize(const Size(800, 600));
tester.binding.window.devicePixelRatioTestValue = 3;
tester.view.devicePixelRatio = 3;
await tester.pumpWidget(
MaterialApp(
debugShowCheckedModeBanner: false,
Expand Down