Skip to content

Commit 47e65e8

Browse files
authored
Use caret syntax with flutter create command (#150920)
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
1 parent 9e1efd8 commit 47e65e8

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/flutter_tools/lib/src/commands/create.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class CreateCommand extends CreateBase {
339339
linux: includeLinux,
340340
macos: includeMacos,
341341
windows: includeWindows,
342-
dartSdkVersionBounds: "'>=$dartSdk <4.0.0'",
342+
dartSdkVersionBounds: '^$dartSdk',
343343
implementationTests: boolArg('implementation-tests'),
344344
agpVersion: gradle.templateAndroidGradlePluginVersion,
345345
kotlinVersion: gradle.templateKotlinGradlePluginVersion,

packages/flutter_tools/test/commands.shard/permeable/create_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,6 +3446,27 @@ void main() {
34463446
expect(pubspec.description, 'a: b');
34473447
});
34483448

3449+
testUsingContext('should use caret syntax in SDK version', () async {
3450+
await _createProject(
3451+
projectDir,
3452+
<String>[
3453+
'--no-pub',
3454+
],
3455+
<String>[
3456+
'pubspec.yaml',
3457+
],
3458+
);
3459+
3460+
final String rawPubspec = await projectDir.childFile('pubspec.yaml').readAsString();
3461+
final Pubspec pubspec = Pubspec.parse(rawPubspec);
3462+
3463+
expect(
3464+
pubspec.environment!['sdk'].toString(),
3465+
startsWith('^'),
3466+
reason: 'The caret syntax is recommended over the traditional syntax.',
3467+
);
3468+
});
3469+
34493470
testUsingContext('create an FFI plugin with ios, then add macos', () async {
34503471
Cache.flutterRoot = '../..';
34513472

0 commit comments

Comments
 (0)