From 47e65e806f753c2b597958f91085cc330e384793 Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Fri, 28 Jun 2024 17:46:34 +0100 Subject: [PATCH] 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** - https://github.com/VGVentures/io_crossword/pull/592#event-13304953743 (cc: @kevmoo) - [Very Good Templates](https://github.com/VeryGoodOpenSource/very_good_templates) relies on the Caret syntax when templating the Dart SDK --- .../lib/src/commands/create.dart | 2 +- .../commands.shard/permeable/create_test.dart | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index ad0d67ca22..9b21bbb7f7 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -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, diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart index 703562449c..9c0e086ab9 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -3446,6 +3446,27 @@ void main() { expect(pubspec.description, 'a: b'); }); + testUsingContext('should use caret syntax in SDK version', () async { + await _createProject( + projectDir, + [ + '--no-pub', + ], + [ + '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 = '../..';