Following coding conventions
Code consistency starts early on, with code formatting. Properly formatted code is easier to read, navigate, and update. While the specifics of what constitutes “properly formatted code” may vary between languages, teams, or individuals, Dart and Flutter have some widely accepted conventions.
For example, some of the Dart and Flutter conventions include the following:
- Limit line length to 80 characters
- Use snake case for file names, but camel case for class names (for example,
my_app.dart
, notMyApp.dart
) - Organize class code in the following order: constructors, factories, fields, methods, and so on
Obviously, everything that applies to Dart also applies to Flutter. However, there is one specific rule that is widely used in the Flutter context: the trailing comma. Due to the nature of Flutter code, where widget trees are often built with multiple levels of nesting, it is considered good practice to use a trailing...