Flame specific lint rules #2277
Replies: 7 comments 40 replies
-
I will start by proposing a lint rule to check if the user is instantiating their game directly on the Bad: class MyGamePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GameWidget(game: MyFlameGame());
}
} Good: class MyGamePage extends StatefulWidget {
@override
State<MyGamePage> createState() => _MyGamePageState();
}
class _MyGamePageState extends State<MyGamePage> {
late final _game = _MyFlameGame();
@override
Widget build(BuildContext context) {
return GameWidget(game: _game);
}
} or class MyGamePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GameWidget.controlled(gameFactory: MyFlameGame.new);
}
} |
Beta Was this translation helpful? Give feedback.
-
A lint rule to check if the It is just a minor thing but it can optimize code in the long run (especially for the internals of Flame it would help out if we ever make extra decisions based on that) ✅ Good: class MyComponent extends Component {
Future<void> onLoad() async {
await ...
}
}
class MyComponent extends Component {
void onLoad() {
...
}
} ❌ Bad: class MyComponent extends Component {
Future<void> onLoad() async {
...
}
} |
Beta Was this translation helpful? Give feedback.
-
I am not sure if this is always a good practice to call super methods in overrides, but if it is then we can add a lint rule.
|
Beta Was this translation helpful? Give feedback.
-
We all probably remember this, but I get forgetful sometimes - do not initialize late final variables in the onMount method. |
Beta Was this translation helpful? Give feedback.
-
Do not create Vector2 in update as well. |
Beta Was this translation helpful? Give feedback.
-
All four rules are now available in prerelease version 5.6.0-dev.1 https://pub.dev/packages/dart_code_metrics/versions/5.6.0-dev.1/changelog! 🚀 Any feedback is very welcome! |
Beta Was this translation helpful? Give feedback.
-
We could create Flame specific lint rules, to help the community avoid bad practices that are specific to the Flame Engine.
I propose that we use this discussion to talk about possible lint rules, and once we agree on a rule, we create an issue out of it.
Thanks so much to @incendial for reaching out to me and suggesting this idea.
Beta Was this translation helpful? Give feedback.
All reactions