Skip to content

Commit

Permalink
Use caret syntax with flutter create command (#150920)
Browse files Browse the repository at this point in the history
The Pull Request changes the `dartSdkVersionBounds` value, which gets templated into the `pubspec.yaml` from the `flutter create`:

https://github.com/flutter/flutter/blob/ffdeaa1995efc1fe7d759e13b92eba1ec57beea6/packages/flutter_tools/templates/app/pubspec.yaml.tmpl#L8

As from the Dart dependencies ["Best practices"](https://dart.dev/tools/pub/dependencies#use-caret-syntax) section of the documentation:

> Use caret syntax
Specify dependencies using the [caret syntax](https://dart.dev/tools/pub/dependencies#caret-syntax). This allows the pub tool to select newer versions of the package when they become available. Further, it places an upper bound on the allowed version.

To learn more about the Caret syntax, refer to the [Caret syntax documentation](https://github.com/flutter/flutter/blob/ffdeaa1995efc1fe7d759e13b92eba1ec57beea6/packages/flutter_tools/templates/app/pubspec.yaml.tmpl#L8).

**Additional context**
- VGVentures/io_crossword#592 (comment) (cc: @kevmoo)
- [Very Good Templates](https://github.com/VeryGoodOpenSource/very_good_templates) relies on the Caret syntax when templating the Dart SDK
  • Loading branch information
alestiago authored Jun 28, 2024
1 parent 9e1efd8 commit 47e65e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/commands/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class CreateCommand extends CreateBase {
linux: includeLinux,
macos: includeMacos,
windows: includeWindows,
dartSdkVersionBounds: "'>=$dartSdk <4.0.0'",
dartSdkVersionBounds: '^$dartSdk',
implementationTests: boolArg('implementation-tests'),
agpVersion: gradle.templateAndroidGradlePluginVersion,
kotlinVersion: gradle.templateKotlinGradlePluginVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3446,6 +3446,27 @@ void main() {
expect(pubspec.description, 'a: b');
});

testUsingContext('should use caret syntax in SDK version', () async {
await _createProject(
projectDir,
<String>[
'--no-pub',
],
<String>[
'pubspec.yaml',
],
);

final String rawPubspec = await projectDir.childFile('pubspec.yaml').readAsString();
final Pubspec pubspec = Pubspec.parse(rawPubspec);

expect(
pubspec.environment!['sdk'].toString(),
startsWith('^'),
reason: 'The caret syntax is recommended over the traditional syntax.',
);
});

testUsingContext('create an FFI plugin with ios, then add macos', () async {
Cache.flutterRoot = '../..';

Expand Down

0 comments on commit 47e65e8

Please sign in to comment.