Fix project name fallback (#150614)
This PR changes the project name logic for `flutter create` to look for the name in the pubspec.yaml `name` field, before falling back to the directory name. Fixes https://github.com/flutter/flutter/issues/53106 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
@@ -824,6 +824,30 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('recreating project uses pubspec name as project name fallback', () async {
|
||||
final Directory outputDirectory = tempDir.childDirectory('invalid-name');
|
||||
|
||||
// Create the new project with a valid project name,
|
||||
// but with a directory name that would be an invalid project name.
|
||||
await _createProject(
|
||||
outputDirectory,
|
||||
<String>['--no-pub', '--template=app', '--project-name', 'valid_name', '--platforms' , 'android'],
|
||||
<String>[]
|
||||
);
|
||||
|
||||
// Now amend a new platform to the project, but omit the project name, so the fallback project name is used.
|
||||
await _createProject(
|
||||
outputDirectory,
|
||||
<String>['--no-pub', '--template=app', '--platforms', 'web'],
|
||||
<String>[]
|
||||
);
|
||||
|
||||
// Verify that the pubspec name was used as project name for the web project.
|
||||
final File webOutputFile = outputDirectory.childDirectory('web').childFile('index.html');
|
||||
|
||||
expect(webOutputFile.readAsStringSync(), contains('<title>valid_name</title>'));
|
||||
});
|
||||
|
||||
testUsingContext('module project with pub', () async {
|
||||
return _createProject(projectDir, <String>[
|
||||
'--template=module',
|
||||
|
||||
Reference in New Issue
Block a user