mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
refactor: Fix lint issues across the codebase - Part 2 (#2677)
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.
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import 'dart:math';
|
||||
|
||||
Random random = Random();
|
||||
final random = Random();
|
||||
|
||||
extension RandomExtension on Random {
|
||||
double fromRange(double min, double max) =>
|
||||
|
||||
@ -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),
|
||||
);
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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',
|
||||
@ -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,
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -68,6 +68,13 @@ class ToolbarButtonState extends ConsumerState<ToolbarButton> {
|
||||
}
|
||||
}
|
||||
|
||||
enum _ToolbarButtonRenderState {
|
||||
disabled,
|
||||
active,
|
||||
hovered,
|
||||
normal,
|
||||
}
|
||||
|
||||
class _ToolbarButtonPainter extends CustomPainter {
|
||||
_ToolbarButtonPainter(
|
||||
this.icon,
|
||||
@ -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();
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user