mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
refactor: Mark semantically final variables as final (or const) proper [DCM] (#2783)
I was playing around with the rule avoid-global-state While I don't think we should enable it, because we do have several totally legitimate cases of what the rule considers global state, it did help me find any current cases where the things just should be final constants. So this PR will mark semantically final variables as final (or const) proper, exclusively on examples (no violations on actual src code are legit).
This commit is contained in:
@ -132,7 +132,7 @@ class MovableEmber extends Ember<FollowComponentExample>
|
|||||||
class Map extends Component {
|
class Map extends Component {
|
||||||
static const double size = 1500;
|
static const double size = 1500;
|
||||||
static const Rect _bounds = Rect.fromLTRB(-size, -size, size, size);
|
static const Rect _bounds = Rect.fromLTRB(-size, -size, size, size);
|
||||||
static Rectangle bounds = Rectangle.fromLTRB(-size, -size, size, size);
|
static final Rectangle bounds = Rectangle.fromLTRB(-size, -size, size, size);
|
||||||
|
|
||||||
static final Paint _paintBorder = Paint()
|
static final Paint _paintBorder = Paint()
|
||||||
..color = Colors.white12
|
..color = Colors.white12
|
||||||
|
|||||||
@ -28,7 +28,8 @@ class _Rectangle extends RectangleComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ClipComponentExample extends FlameGame with TapDetector {
|
class ClipComponentExample extends FlameGame with TapDetector {
|
||||||
static String description = 'Tap on the objects to increase their size.';
|
static const String description =
|
||||||
|
'Tap on the objects to increase their size.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onLoad() async {
|
Future<void> onLoad() async {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import 'package:provider/provider.dart';
|
|||||||
class ComponentsNotifierProviderExampleWidget extends StatefulWidget {
|
class ComponentsNotifierProviderExampleWidget extends StatefulWidget {
|
||||||
const ComponentsNotifierProviderExampleWidget({super.key});
|
const ComponentsNotifierProviderExampleWidget({super.key});
|
||||||
|
|
||||||
static String description = '''
|
static const String description = '''
|
||||||
Similar to the Components Notifier example, but uses provider
|
Similar to the Components Notifier example, but uses provider
|
||||||
instead of the built in ComponentsNotifierBuilder widget.
|
instead of the built in ComponentsNotifierBuilder widget.
|
||||||
''';
|
''';
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import 'package:flame/input.dart';
|
|||||||
import 'package:flame/math.dart';
|
import 'package:flame/math.dart';
|
||||||
|
|
||||||
class SpawnComponentExample extends FlameGame with TapDetector {
|
class SpawnComponentExample extends FlameGame with TapDetector {
|
||||||
static String description =
|
static const String description =
|
||||||
'Tap on the screen to start spawning Embers within different shapes.';
|
'Tap on the screen to start spawning Embers within different shapes.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -4,8 +4,8 @@ import 'package:flame/text.dart';
|
|||||||
import 'package:flutter/painting.dart';
|
import 'package:flutter/painting.dart';
|
||||||
|
|
||||||
class RichTextExample extends FlameGame {
|
class RichTextExample extends FlameGame {
|
||||||
static String description = 'A non-interactive example of how to render rich '
|
static const String description =
|
||||||
'text in Flame.';
|
'A non-interactive example of how to render rich text in Flame.';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Color backgroundColor() => const Color(0xFF888888);
|
Color backgroundColor() => const Color(0xFF888888);
|
||||||
|
|||||||
@ -38,8 +38,8 @@ class Square extends RectangleComponent with TapCallbacks {
|
|||||||
static const squareSize = 128.0;
|
static const squareSize = 128.0;
|
||||||
static const indicatorSize = 6.0;
|
static const indicatorSize = 6.0;
|
||||||
|
|
||||||
static Paint red = BasicPalette.red.paint();
|
static final Paint red = BasicPalette.red.paint();
|
||||||
static Paint blue = BasicPalette.blue.paint();
|
static final Paint blue = BasicPalette.blue.paint();
|
||||||
|
|
||||||
Square(Vector2 position)
|
Square(Vector2 position)
|
||||||
: super(
|
: super(
|
||||||
|
|||||||
@ -18,9 +18,9 @@ void main() {
|
|||||||
/// for tapping elsewhere.
|
/// for tapping elsewhere.
|
||||||
/// 3. Uses the Bgm utility for background music.
|
/// 3. Uses the Bgm utility for background music.
|
||||||
class AudioGame extends FlameGame with TapDetector {
|
class AudioGame extends FlameGame with TapDetector {
|
||||||
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),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,9 @@ class GameMap extends Component with HasGameReference<ColonistsGame> {
|
|||||||
static const mapSizeY = 50;
|
static const mapSizeY = 50;
|
||||||
static const totalPositions = mapSizeX * mapSizeY;
|
static const totalPositions = mapSizeX * mapSizeY;
|
||||||
|
|
||||||
static int cheeseSpread = (0.03 * totalPositions).toInt();
|
static final int cheeseSpread = (0.03 * totalPositions).toInt();
|
||||||
static int breadSpread = (0.05 * totalPositions).toInt();
|
static final int breadSpread = (0.05 * totalPositions).toInt();
|
||||||
static int workerSpread = (0.1 * totalPositions).toInt();
|
static final int workerSpread = (0.1 * totalPositions).toInt();
|
||||||
|
|
||||||
static const double workerMinSpeed = 25;
|
static const double workerMinSpeed = 25;
|
||||||
static const double workerMaxSpeed = 75;
|
static const double workerMaxSpeed = 75;
|
||||||
|
|||||||
Reference in New Issue
Block a user