Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

flutter create refuses the project name

Error"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.

  • Applies to Flutter 3.3x stable, Dart 3.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.yaml
  2. 2Match what you see, then jump to its fix

    1. 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. 2The 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. 3Invalid project name: 'flutter' - this will conflict with Flutter package dependencies.The name equals a package Flutter itself depends onFix

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_app

3Verify

The command finishes without the name error and pubspec.yaml shows the name.

grep '^name:' pubspec.yaml

Confirmed by dart.dev

Did this fix it?

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 get

Confirmed by dart.dev

Did this fix it?

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.yaml

2Fix

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 analyze

Confirmed by raw.githubusercontent.com

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.