Skip to content

Commit

Permalink
refactor: Fix lint issues across the codebase - Part 2 (#2677)
Browse files Browse the repository at this point in the history
Fix a handful of lint issues across the codebase, identified using DCM.
Nothing controversial, I expect; slowly getting these out of the way so
we can focus on discussing bigger things.
  • Loading branch information
luanpotter committed Aug 25, 2023
1 parent 75aee76 commit 10e4109
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 33 deletions.
4 changes: 2 additions & 2 deletions examples/games/padracing/lib/padracing_game.dart
Expand Up @@ -44,8 +44,8 @@ class PadRacingGame extends Forge2DGame with KeyboardEvents {
@override
Color backgroundColor() => Colors.black;

static Vector2 trackSize = Vector2.all(500);
static double playZoom = 8.0;
static final Vector2 trackSize = Vector2.all(500);
static const double playZoom = 8.0;
static const int numberOfLaps = 3;
late final World cameraWorld;
late CameraComponent startCamera;
Expand Down
7 changes: 4 additions & 3 deletions examples/games/padracing/lib/tire.dart
Expand Up @@ -69,9 +69,10 @@ class Tire extends BodyComponent<PadRacingGame> {

@override
Body createBody() {
final jointAnchor = isFrontTire
? Vector2(isLeftTire ? -3.0 : 3.0, 3.5)
: Vector2(isLeftTire ? -3.0 : 3.0, -4.25);
final jointAnchor = Vector2(
isLeftTire ? -3.0 : 3.0,
isFrontTire ? 3.5 : -4.25,
);

final def = BodyDef()
..type = BodyType.dynamic
Expand Down
Expand Up @@ -6,7 +6,7 @@ import 'package:rogue_shooter/rogue_shooter_game.dart';
class EnemyComponent extends SpriteAnimationComponent
with HasGameRef<RogueShooterGame>, CollisionCallbacks {
static const speed = 150;
static Vector2 initialSize = Vector2.all(25);
static final Vector2 initialSize = Vector2.all(25);

EnemyComponent({required super.position})
: super(size: initialSize, anchor: Anchor.center);
Expand Down
2 changes: 1 addition & 1 deletion examples/games/trex/lib/background/cloud.dart
Expand Up @@ -15,7 +15,7 @@ class Cloud extends SpriteComponent
size: initialSize,
);

static Vector2 initialSize = Vector2(92.0, 28.0);
static final Vector2 initialSize = Vector2(92.0, 28.0);

static const double maxCloudGap = 400.0;
static const double minCloudGap = 100.0;
Expand Down
2 changes: 1 addition & 1 deletion examples/games/trex/lib/random_extension.dart
@@ -1,6 +1,6 @@
import 'dart:math';

Random random = Random();
final random = Random();

extension RandomExtension on Random {
double fromRange(double min, double max) =>
Expand Down
Expand Up @@ -17,9 +17,9 @@ class BasicAudioExample extends FlameGame with TapDetector {
3. Uses the Bgm utility for background music.
''';

static Paint black = BasicPalette.black.paint();
static Paint gray = const PaletteEntry(Color(0xFFCCCCCC)).paint();
static TextPaint text = TextPaint(
static final Paint black = BasicPalette.black.paint();
static final Paint gray = const PaletteEntry(Color(0xFFCCCCCC)).paint();
static final TextPaint text = TextPaint(
style: TextStyle(color: BasicPalette.white.color),
);

Expand Down
10 changes: 5 additions & 5 deletions examples/lib/stories/input/hardware_keyboard_example.dart
Expand Up @@ -7,7 +7,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

class HardwareKeyboardExample extends FlameGame {
static String description = '''
static const String description = '''
This example uses the HardwareKeyboardDetector mixin in order to keep
track of which keys on a keyboard are currently pressed.
Expand Down Expand Up @@ -67,7 +67,7 @@ class MyKeyboardDetector extends HardwareKeyboardDetector
/// The names of keyboard keys (at least the most important ones). We can't
/// rely on `key.debugName` because this property is not available in release
/// builds.
static Map<PhysicalKeyboardKey, String> keyNames = {
static final Map<PhysicalKeyboardKey, String> keyNames = {
PhysicalKeyboardKey.hyper: 'Hyper',
PhysicalKeyboardKey.superKey: 'Super',
PhysicalKeyboardKey.fn: 'Fn',
Expand Down Expand Up @@ -233,12 +233,12 @@ class KeyboardKey extends PositionComponent {
/// they are waiting to be removed.
bool visible = true;

static Vector2 padding = Vector2(24, 12);
static Paint borderPaint = Paint()
static final Vector2 padding = Vector2(24, 12);
static final Paint borderPaint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 3
..color = const Color(0xffb5ffd0);
static TextPaint textRenderer = TextPaint(
static final TextPaint textRenderer = TextPaint(
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
Expand Down
Expand Up @@ -46,8 +46,10 @@ class SpriteButtonComponent extends SpriteGroupComponent<ButtonState>
button != null,
'The button sprite has to be set either in onLoad or in the constructor',
);
sprites = {ButtonState.up: button!};
sprites![ButtonState.down] = buttonDown ?? button!;
sprites = {
ButtonState.up: button!,
ButtonState.down: buttonDown ?? button!,
};
super.onMount();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flame_studio/lib/src/core/component_tree.dart
Expand Up @@ -63,7 +63,7 @@ class ComponentTreeObserver extends StateNotifier<ComponentTreeState> {
}
}

static Duration refreshFrequency = const Duration(milliseconds: 300);
static const Duration refreshFrequency = Duration(milliseconds: 300);

void _refresh() {
if (!mounted) {
Expand Down
48 changes: 34 additions & 14 deletions packages/flame_studio/lib/src/widgets/toolbar/toolbar_button.dart
Expand Up @@ -68,6 +68,13 @@ class ToolbarButtonState extends ConsumerState<ToolbarButton> {
}
}

enum _ToolbarButtonRenderState {
disabled,
active,
hovered,
normal,
}

class _ToolbarButtonPainter extends CustomPainter {
_ToolbarButtonPainter(
this.icon,
Expand All @@ -89,26 +96,26 @@ class _ToolbarButtonPainter extends CustomPainter {
canvas.save();
canvas.scale(size.height / 20.0);

final renderState = _renderState;

final radius = Radius.circular(theme.buttonRadius);
final color = isDisabled
? theme.buttonDisabledColor
: isActive
? theme.buttonActiveColor
: isHovered
? theme.buttonHoverColor
: theme.buttonColor;
final color = switch (renderState) {
_ToolbarButtonRenderState.disabled => theme.buttonDisabledColor,
_ToolbarButtonRenderState.active => theme.buttonActiveColor,
_ToolbarButtonRenderState.hovered => theme.buttonHoverColor,
_ToolbarButtonRenderState.normal => theme.buttonColor,
};
canvas.drawRRect(
RRect.fromLTRBR(0, 0, size.width / scale, 20.0, radius),
Paint()..color = color,
);

final textColor = isDisabled
? theme.buttonDisabledTextColor
: isActive
? theme.buttonActiveTextColor
: isHovered
? theme.buttonHoverTextColor
: theme.buttonTextColor;
final textColor = switch (renderState) {
_ToolbarButtonRenderState.disabled => theme.buttonDisabledTextColor,
_ToolbarButtonRenderState.active => theme.buttonActiveTextColor,
_ToolbarButtonRenderState.hovered => theme.buttonHoverTextColor,
_ToolbarButtonRenderState.normal => theme.buttonTextColor,
};
canvas.translate(size.width / scale / 2, 10);
canvas.drawPath(icon, Paint()..color = textColor);
canvas.restore();
Expand All @@ -121,4 +128,17 @@ class _ToolbarButtonPainter extends CustomPainter {
isDisabled != old.isDisabled ||
icon != old.icon;
}

_ToolbarButtonRenderState get _renderState {
if (isDisabled) {
return _ToolbarButtonRenderState.disabled;
}
if (isActive) {
return _ToolbarButtonRenderState.active;
}
if (isHovered) {
return _ToolbarButtonRenderState.hovered;
}
return _ToolbarButtonRenderState.normal;
}
}

0 comments on commit 10e4109

Please sign in to comment.