The InnoQ organization formalizes the unified guide to writing code in Dart/Flutter based off of the official Effective Dart guidelines as follows:
Our style guide includes three most widely used flavors of naming Identifiers:
- UpperCamelCase (classes, enums, typedefs, type parameters, annotations)
class HttpRequest {
/*...*/
}
typedef Predicate<T> = bool Function(T value);- lowercase_with_underscores (libraries, packages, directories, source files, 'as' imports)
import 'package:angular_components/angular_components.dart' as angular_components;- lowerCamelCase (other identifiers, vars, consts, finals, functions, etc.)
const pi = 3.14;
const defaultTimeout = 1000;
final urlScheme = RegExp('^([a-z]+):');
class Dice {
static final numberGenerator = Random();
}Important: Effective Dart says you can use SCREAMING_CAPS to comply with legacy code. As we do not work with legacy, our code style does not allow SCREAMING_CAPS at all. If you find yourself needing to use it, this means that you need refactor the code, so that you do not work with such legacy code.
- Abbreviations: write no-caps.
class HttpConnection {}
class DBIOPort {}
class TVVcr {}
class MrRogers {}
var httpRequest = 1;
var uiHandler = 2;
var userId = 3;
Id id;Good:
futureOfVoid.then((_) {
print('Operation complete.');
});Bad:
_functionWithoutReturnType(Map<String, int> abacaba) {
print(1);
print(2);
// 123
}This seems to not be implemented by default, so we implemented it ourselves:

For the bad code up above this is what the analyzer finds with the new lint rule:

And the problem is resolved as we rename abacaba to _
It also works with __, ___, and other number of underscores!
If you're not returning a dynamic, but void
then you need to always specify the return type explicitly for the function.
Good:
void _doSomething() {
print("Doing something...");
}Bad:
_doSomething() {
print("Doing something...");
}We have made a custom linting rule for this specific style guide point:
See the last chapter of this markdown to fire custom lints
Write return; instead of return null; for functions returning void.
Bad: kDefaultTimeout
directives_ordering
Good:
import 'dart:async';
import 'dart:html';
import 'package:bar/bar.dart';
import 'package:foo/foo.dart';
import 'util.dart';
export 'src/error.dart';lines_longer_than_80_chars
curly_braces_in_flow_control_structures
Good:
if (isWeekDay) {
print('Bike to work!');
} else {
print('Go dancing or read a book!');
}
if (arg == null) return defaultValue;Bad:
if (overflowChars != other.overflowChars)
return overflowChars < other.overflowChars;https://github.com/dart-lang/dart_style/wiki/Formatting-Rules
dart run custom_lint to run custom linting rules that our team wrote
if dart analyze does not work