flutter create refuses the project name
"MyApp" is not a valid Dart package name.Short answer
flutter create checks the project name against Dart's package rules: lowercase letters, digits and underscores only, no leading digit, no reserved word, and not flutter, flutter_test, collection or meta. The name comes from --project-name, an existing pubspec.yaml, or the folder name, in that order. Rename the folder or pass --project-name.
Fix it fast
1Find out which cause you have
Read the name inside the first quoted part of the message. That is the string Flutter rejected. Then check where it came from: the tool takes --project-name if given, otherwise the name field of a pubspec.yaml already in the target folder, otherwise the folder name.
pwd ls pubspec.yaml 2>/dev/null && grep '^name:' pubspec.yaml2Match what you see, then jump to its fix
- 1
"my-app" is not a valid Dart package name. (or MyApp, my app, my.app)Capital letters, hyphens, spaces or dots in the nameFix - 2
The same "is not a valid Dart package name" message for names like 2048_game or classThe name starts with a digit or is a Dart reserved wordFix - 3
Invalid project name: 'flutter' - this will conflict with Flutter package dependencies.The name equals a package Flutter itself depends onFix
- 1
What does the error look like?
"MyApp" is not a valid Dart package name.The name should consist of lowercase words separated by underscores, "like_this".Use only basic Latin letters and Arabic digits: [a-z0-9_], and ensure the name is a valid Dart identifier (i.e. it does not start with a digit and is not a reserved word).Invalid project name: 'flutter' - this will conflict with Flutter package dependencies.
Cause 1 of 3
Capital letters, hyphens, spaces or dots in the name
1Check
Dart package names may use only [a-z0-9_]. A hyphen, a space, a dot or any capital letter breaks the rule. When you run flutter create in an existing folder, the folder name is used as written, so a folder called My-App fails even though you typed nothing wrong.
basename "$PWD"2Fix
Create the project under a valid name, and keep a friendlier display name for the app elsewhere. You can leave the folder name alone and pass the package name yourself.
flutter create --project-name my_app .
# or from the parent folder
flutter create my_app3Verify
The command finishes without the name error and pubspec.yaml shows the name.
grep '^name:' pubspec.yamlConfirmed by dart.dev
Cause 2 of 3
The name starts with a digit or is a Dart reserved word
1Check
The name must also be a valid Dart identifier. That rules out a leading digit and words such as class or if.
printf '%s\n' "2048_game" | grep -E '^[0-9]'2Fix
Put a letter or a word in front of a leading digit, or choose another word instead of the reserved one.
flutter create --project-name game_2048 .3Verify
flutter create now runs to the end and prints the folder summary.
flutter pub getConfirmed by dart.dev
Cause 3 of 3
The name equals a package Flutter itself depends on
1Check
The Flutter tool keeps a short list of names that would collide with the dependencies of every new project: collection, flutter, flutter_test and meta. A project with one of these names cannot depend on the real package.
grep '^name:' pubspec.yaml2Fix
Pick a name that is not on that list, for example one with your product name in front of it.
flutter create --project-name acme_flutter_demo .3Verify
The create command completes.
flutter analyzeConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Name folders for Flutter projects in lowercase with underscores from the start.
- Pass --project-name when the folder name must stay as it is.
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