mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +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 |   @override | ||||||
|   Color backgroundColor() => Colors.black; |   Color backgroundColor() => Colors.black; | ||||||
|  |  | ||||||
|   static Vector2 trackSize = Vector2.all(500); |   static final Vector2 trackSize = Vector2.all(500); | ||||||
|   static double playZoom = 8.0; |   static const double playZoom = 8.0; | ||||||
|   static const int numberOfLaps = 3; |   static const int numberOfLaps = 3; | ||||||
|   late final World cameraWorld; |   late final World cameraWorld; | ||||||
|   late CameraComponent startCamera; |   late CameraComponent startCamera; | ||||||
|  | |||||||
| @ -69,9 +69,10 @@ class Tire extends BodyComponent<PadRacingGame> { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Body createBody() { |   Body createBody() { | ||||||
|     final jointAnchor = isFrontTire |     final jointAnchor = Vector2( | ||||||
|         ? Vector2(isLeftTire ? -3.0 : 3.0, 3.5) |       isLeftTire ? -3.0 : 3.0, | ||||||
|         : Vector2(isLeftTire ? -3.0 : 3.0, -4.25); |       isFrontTire ? 3.5 : -4.25, | ||||||
|  |     ); | ||||||
|  |  | ||||||
|     final def = BodyDef() |     final def = BodyDef() | ||||||
|       ..type = BodyType.dynamic |       ..type = BodyType.dynamic | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import 'package:rogue_shooter/rogue_shooter_game.dart'; | |||||||
| class EnemyComponent extends SpriteAnimationComponent | class EnemyComponent extends SpriteAnimationComponent | ||||||
|     with HasGameRef<RogueShooterGame>, CollisionCallbacks { |     with HasGameRef<RogueShooterGame>, CollisionCallbacks { | ||||||
|   static const speed = 150; |   static const speed = 150; | ||||||
|   static Vector2 initialSize = Vector2.all(25); |   static final Vector2 initialSize = Vector2.all(25); | ||||||
|  |  | ||||||
|   EnemyComponent({required super.position}) |   EnemyComponent({required super.position}) | ||||||
|       : super(size: initialSize, anchor: Anchor.center); |       : super(size: initialSize, anchor: Anchor.center); | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ class Cloud extends SpriteComponent | |||||||
|           size: initialSize, |           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 maxCloudGap = 400.0; | ||||||
|   static const double minCloudGap = 100.0; |   static const double minCloudGap = 100.0; | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| import 'dart:math'; | import 'dart:math'; | ||||||
|  |  | ||||||
| Random random = Random(); | final random = Random(); | ||||||
|  |  | ||||||
| extension RandomExtension on Random { | extension RandomExtension on Random { | ||||||
|   double fromRange(double min, double max) => |   double fromRange(double min, double max) => | ||||||
|  | |||||||
| @ -17,9 +17,9 @@ class BasicAudioExample extends FlameGame with TapDetector { | |||||||
|     3. Uses the Bgm utility for background music. |     3. Uses the Bgm utility for background music. | ||||||
|   '''; |   '''; | ||||||
|  |  | ||||||
|   static Paint black = BasicPalette.black.paint(); |   static final Paint black = BasicPalette.black.paint(); | ||||||
|   static Paint gray = const PaletteEntry(Color(0xFFCCCCCC)).paint(); |   static final Paint gray = const PaletteEntry(Color(0xFFCCCCCC)).paint(); | ||||||
|   static TextPaint text = TextPaint( |   static final TextPaint text = TextPaint( | ||||||
|     style: TextStyle(color: BasicPalette.white.color), |     style: TextStyle(color: BasicPalette.white.color), | ||||||
|   ); |   ); | ||||||
|  |  | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import 'package:flutter/rendering.dart'; | |||||||
| import 'package:flutter/services.dart'; | import 'package:flutter/services.dart'; | ||||||
|  |  | ||||||
| class HardwareKeyboardExample extends FlameGame { | class HardwareKeyboardExample extends FlameGame { | ||||||
|   static String description = ''' |   static const String description = ''' | ||||||
|     This example uses the HardwareKeyboardDetector mixin in order to keep |     This example uses the HardwareKeyboardDetector mixin in order to keep | ||||||
|     track of which keys on a keyboard are currently pressed. |     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 |   /// 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 |   /// rely on `key.debugName` because this property is not available in release | ||||||
|   /// builds. |   /// builds. | ||||||
|   static Map<PhysicalKeyboardKey, String> keyNames = { |   static final Map<PhysicalKeyboardKey, String> keyNames = { | ||||||
|     PhysicalKeyboardKey.hyper: 'Hyper', |     PhysicalKeyboardKey.hyper: 'Hyper', | ||||||
|     PhysicalKeyboardKey.superKey: 'Super', |     PhysicalKeyboardKey.superKey: 'Super', | ||||||
|     PhysicalKeyboardKey.fn: 'Fn', |     PhysicalKeyboardKey.fn: 'Fn', | ||||||
| @ -233,12 +233,12 @@ class KeyboardKey extends PositionComponent { | |||||||
|   /// they are waiting to be removed. |   /// they are waiting to be removed. | ||||||
|   bool visible = true; |   bool visible = true; | ||||||
|  |  | ||||||
|   static Vector2 padding = Vector2(24, 12); |   static final Vector2 padding = Vector2(24, 12); | ||||||
|   static Paint borderPaint = Paint() |   static final Paint borderPaint = Paint() | ||||||
|     ..style = PaintingStyle.stroke |     ..style = PaintingStyle.stroke | ||||||
|     ..strokeWidth = 3 |     ..strokeWidth = 3 | ||||||
|     ..color = const Color(0xffb5ffd0); |     ..color = const Color(0xffb5ffd0); | ||||||
|   static TextPaint textRenderer = TextPaint( |   static final TextPaint textRenderer = TextPaint( | ||||||
|     style: const TextStyle( |     style: const TextStyle( | ||||||
|       fontSize: 20, |       fontSize: 20, | ||||||
|       fontWeight: FontWeight.bold, |       fontWeight: FontWeight.bold, | ||||||
|  | |||||||
| @ -46,8 +46,10 @@ class SpriteButtonComponent extends SpriteGroupComponent<ButtonState> | |||||||
|       button != null, |       button != null, | ||||||
|       'The button sprite has to be set either in onLoad or in the constructor', |       'The button sprite has to be set either in onLoad or in the constructor', | ||||||
|     ); |     ); | ||||||
|     sprites = {ButtonState.up: button!}; |     sprites = { | ||||||
|     sprites![ButtonState.down] = buttonDown ?? button!; |       ButtonState.up: button!, | ||||||
|  |       ButtonState.down: buttonDown ?? button!, | ||||||
|  |     }; | ||||||
|     super.onMount(); |     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() { |   void _refresh() { | ||||||
|     if (!mounted) { |     if (!mounted) { | ||||||
|  | |||||||
| @ -68,6 +68,13 @@ class ToolbarButtonState extends ConsumerState<ToolbarButton> { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | enum _ToolbarButtonRenderState { | ||||||
|  |   disabled, | ||||||
|  |   active, | ||||||
|  |   hovered, | ||||||
|  |   normal, | ||||||
|  | } | ||||||
|  |  | ||||||
| class _ToolbarButtonPainter extends CustomPainter { | class _ToolbarButtonPainter extends CustomPainter { | ||||||
|   _ToolbarButtonPainter( |   _ToolbarButtonPainter( | ||||||
|     this.icon, |     this.icon, | ||||||
| @ -89,26 +96,26 @@ class _ToolbarButtonPainter extends CustomPainter { | |||||||
|     canvas.save(); |     canvas.save(); | ||||||
|     canvas.scale(size.height / 20.0); |     canvas.scale(size.height / 20.0); | ||||||
|  |  | ||||||
|  |     final renderState = _renderState; | ||||||
|  |  | ||||||
|     final radius = Radius.circular(theme.buttonRadius); |     final radius = Radius.circular(theme.buttonRadius); | ||||||
|     final color = isDisabled |     final color = switch (renderState) { | ||||||
|         ? theme.buttonDisabledColor |       _ToolbarButtonRenderState.disabled => theme.buttonDisabledColor, | ||||||
|         : isActive |       _ToolbarButtonRenderState.active => theme.buttonActiveColor, | ||||||
|             ? theme.buttonActiveColor |       _ToolbarButtonRenderState.hovered => theme.buttonHoverColor, | ||||||
|             : isHovered |       _ToolbarButtonRenderState.normal => theme.buttonColor, | ||||||
|                 ? theme.buttonHoverColor |     }; | ||||||
|                 : theme.buttonColor; |  | ||||||
|     canvas.drawRRect( |     canvas.drawRRect( | ||||||
|       RRect.fromLTRBR(0, 0, size.width / scale, 20.0, radius), |       RRect.fromLTRBR(0, 0, size.width / scale, 20.0, radius), | ||||||
|       Paint()..color = color, |       Paint()..color = color, | ||||||
|     ); |     ); | ||||||
|  |  | ||||||
|     final textColor = isDisabled |     final textColor = switch (renderState) { | ||||||
|         ? theme.buttonDisabledTextColor |       _ToolbarButtonRenderState.disabled => theme.buttonDisabledTextColor, | ||||||
|         : isActive |       _ToolbarButtonRenderState.active => theme.buttonActiveTextColor, | ||||||
|             ? theme.buttonActiveTextColor |       _ToolbarButtonRenderState.hovered => theme.buttonHoverTextColor, | ||||||
|             : isHovered |       _ToolbarButtonRenderState.normal => theme.buttonTextColor, | ||||||
|                 ? theme.buttonHoverTextColor |     }; | ||||||
|                 : theme.buttonTextColor; |  | ||||||
|     canvas.translate(size.width / scale / 2, 10); |     canvas.translate(size.width / scale / 2, 10); | ||||||
|     canvas.drawPath(icon, Paint()..color = textColor); |     canvas.drawPath(icon, Paint()..color = textColor); | ||||||
|     canvas.restore(); |     canvas.restore(); | ||||||
| @ -121,4 +128,17 @@ class _ToolbarButtonPainter extends CustomPainter { | |||||||
|         isDisabled != old.isDisabled || |         isDisabled != old.isDisabled || | ||||||
|         icon != old.icon; |         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
	 Luan Nico
					Luan Nico