The meta package provides a @required
annotation that is supported by the DartAnalyzer.
Flutter uses this a lot and provides @required
directly from import 'package:flutter/foundation.dart'
foo({@required String name}) {...}
foo(); // results in static warning
@required
doesn’t check if the passed value is null
or not, only that a value was actually passed on the call site.
To check for null
you can also use assert()
to check for passed values
class Ability {
Ability(this.name, this.effectDuration, this.recast) : assert(name != null), assert(effectDuration != null), assert(recast != null);
final name;
final effectDuration;
final recast; // wait time until next use
// ...
}