Skip to content

Commit

Permalink
refactor: Mark semantically final variables as final (or const) prope…
Browse files Browse the repository at this point in the history
…r [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).
  • Loading branch information
luanpotter committed Oct 2, 2023
1 parent a036f19 commit 71f7b47
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
Expand Up @@ -132,7 +132,7 @@ class MovableEmber extends Ember<FollowComponentExample>
class Map extends Component {
static const double size = 1500;
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()
..color = Colors.white12
Expand Down
3 changes: 2 additions & 1 deletion examples/lib/stories/components/clip_component_example.dart
Expand Up @@ -28,7 +28,8 @@ class _Rectangle extends RectangleComponent {
}

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
Future<void> onLoad() async {
Expand Down
Expand Up @@ -7,7 +7,7 @@ import 'package:provider/provider.dart';
class ComponentsNotifierProviderExampleWidget extends StatefulWidget {
const ComponentsNotifierProviderExampleWidget({super.key});

static String description = '''
static const String description = '''
Similar to the Components Notifier example, but uses provider
instead of the built in ComponentsNotifierBuilder widget.
''';
Expand Down
Expand Up @@ -7,7 +7,7 @@ import 'package:flame/input.dart';
import 'package:flame/math.dart';

class SpawnComponentExample extends FlameGame with TapDetector {
static String description =
static const String description =
'Tap on the screen to start spawning Embers within different shapes.';

@override
Expand Down
4 changes: 2 additions & 2 deletions examples/lib/stories/rendering/rich_text_example.dart
Expand Up @@ -4,8 +4,8 @@ import 'package:flame/text.dart';
import 'package:flutter/painting.dart';

class RichTextExample extends FlameGame {
static String description = 'A non-interactive example of how to render rich '
'text in Flame.';
static const String description =
'A non-interactive example of how to render rich text in Flame.';

@override
Color backgroundColor() => const Color(0xFF888888);
Expand Down
4 changes: 2 additions & 2 deletions packages/flame/example/lib/main.dart
Expand Up @@ -38,8 +38,8 @@ class Square extends RectangleComponent with TapCallbacks {
static const squareSize = 128.0;
static const indicatorSize = 6.0;

static Paint red = BasicPalette.red.paint();
static Paint blue = BasicPalette.blue.paint();
static final Paint red = BasicPalette.red.paint();
static final Paint blue = BasicPalette.blue.paint();

Square(Vector2 position)
: super(
Expand Down
6 changes: 3 additions & 3 deletions packages/flame_audio/example/lib/main.dart
Expand Up @@ -18,9 +18,9 @@ void main() {
/// for tapping elsewhere.
/// 3. Uses the Bgm utility for background music.
class AudioGame extends FlameGame with TapDetector {
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
6 changes: 3 additions & 3 deletions packages/flame_isolate/example/lib/game_map/game_map.dart
Expand Up @@ -18,9 +18,9 @@ class GameMap extends Component with HasGameReference<ColonistsGame> {
static const mapSizeY = 50;
static const totalPositions = mapSizeX * mapSizeY;

static int cheeseSpread = (0.03 * totalPositions).toInt();
static int breadSpread = (0.05 * totalPositions).toInt();
static int workerSpread = (0.1 * totalPositions).toInt();
static final int cheeseSpread = (0.03 * totalPositions).toInt();
static final int breadSpread = (0.05 * totalPositions).toInt();
static final int workerSpread = (0.1 * totalPositions).toInt();

static const double workerMinSpeed = 25;
static const double workerMaxSpeed = 75;
Expand Down

0 comments on commit 71f7b47

Please sign in to comment.