Dart error: the parameter can't have a value of 'null' because of its type
The parameter 'title' can't have a value of 'null' because of its type, but the implicit default value is 'null'.Short answer
An optional parameter that is not passed gets the value null. If its type is non-nullable, such as String or int, Dart refuses to compile. Pick one: make the type nullable with a question mark, give it a non-null default, or make a named parameter required.
Fix it fast
1Find out which cause you have
Run the analyzer. The message names the parameter and the file and line of the constructor or function.
dart analyze2Match what you see, then jump to its fix
- 1
The parameter is inside curly braces, for example {this.title}, and its type has no question markA named parameter has no default and is not requiredFix - 2
Callers sometimes have no value to send, and null should mean no valueThe value is genuinely optionalFix - 3
A missing value should behave like a known value, such as 0 or an empty stringA sensible default existsFix - 4
The argument type 'String?' can't be assigned to the parameter type 'String'A nullable value is passed to a non-nullable parameterFix
- 1
What does the error look like?
The parameter 'title' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Cause 1 of 4
A named parameter has no default and is not required
1Check
Named parameters are optional by default. When the caller leaves one out, it is null, which a non-nullable type cannot hold.
grep -rn "this\." lib/ | grep "{" | head2Fix
If the caller must always send it, add required. This is the usual choice for widget constructors.
class Card extends StatelessWidget {
const Card({super.key, required this.title});
final String title;
// ...
}3Verify
The analyzer reports no issue for the file.
dart analyzeConfirmed by dart.dev
Cause 2 of 4
The value is genuinely optional
1Check
Decide what a missing value means. If null is a valid answer, the type should say so.
dart analyze2Fix
Add a question mark to the type, then handle null where the value is used, for example with a null check or ??.
void show({String? note}) {
print(note ?? 'No note');
}3Verify
The call without the argument compiles and prints the fallback.
dart analyzeConfirmed by dart.dev
Cause 3 of 4
A sensible default exists
1Check
Look for a value that is safe whenever the caller says nothing.
dart analyze2Fix
Write the default in the parameter list. Optional positional parameters work the same way.
void load({int retries = 3}) {}
void pad([int width = 1]) {}3Verify
Calls with and without the argument both compile.
dart analyzeConfirmed by dart.dev
Cause 4 of 4
A nullable value is passed to a non-nullable parameter
1Check
This is the sibling error. The parameter is fine; the value you pass may be null, for example a field or a map lookup.
dart analyze2Fix
Test the local value before passing it. Dart narrows a local variable after a null check. A field is not narrowed, so copy it into a local variable first.
final name = user.name; // a nullable field
if (name != null) {
greet(name);
}3Verify
The analyzer accepts the call inside the if block.
dart analyzeConfirmed by dart.dev
How do I stop it coming back?
- Write required on named constructor parameters unless a missing value has a clear meaning.
- Make a type nullable only when null is a real state in your data.
- Run dart analyze in CI so the error never reaches a release branch.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
AudioCache has no play method after updating audioplayers
The method 'play' isn't defined for the type 'AudioCache'.
Since audioplayers 1.0, AudioCache only turns asset files into local files and caches them.
2 causes, each with a fixMobile apps
Flutter Bloc throws that emit was called after the event handler completed
emit was called after an event handler completed normally.
Each on<Event> handler gets its own Emitter, and it stops working the moment the handler's returned Future completes.
2 causes, each with a fixMobile apps
analysis_options.yaml: the URI it includes can't be found
include_file_not_found
The analyzer reports include_file_not_found when the file named after include: in analysis_options.yaml does not resolve.
2 causes, each with a fixMobile apps
Dart error: the body might complete normally and return null for a non-nullable type
body_might_complete_normally
Dart found a path through your function or callback that reaches the closing brace without a return.
3 causes, each with a fixMobile apps
Dart throws ConcurrentModificationError while looping over a list
ConcurrentModificationError
Dart throws this when a collection changes size while something iterates it.
2 causes, each with a fixMobile apps
Dart cannot turn a compact timestamp like 20201101153000 into a DateTime
FormatException: Invalid date format
DateTime.parse accepts a subset of ISO 8601, and a time part must be introduced by T or a space.
2 causes, each with a fix