Unverified Commit 63267e90 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Make flutter create --smaple null-safe (#74844)

parent d11fe856
...@@ -236,6 +236,8 @@ class CreateCommand extends CreateBase { ...@@ -236,6 +236,8 @@ class CreateCommand extends CreateBase {
linux: featureFlags.isLinuxEnabled && platforms.contains('linux'), linux: featureFlags.isLinuxEnabled && platforms.contains('linux'),
macos: featureFlags.isMacOSEnabled && platforms.contains('macos'), macos: featureFlags.isMacOSEnabled && platforms.contains('macos'),
windows: featureFlags.isWindowsEnabled && platforms.contains('windows'), windows: featureFlags.isWindowsEnabled && platforms.contains('windows'),
// Enable null-safety for sample code, which is - unlike our regular templates - already migrated.
dartSdkVersionBounds: sampleCode != null ? '">=2.12.0-0 <3.0.0"' : '">=2.7.0 <3.0.0"'
); );
final String relativeDirPath = globals.fs.path.relative(projectDirPath); final String relativeDirPath = globals.fs.path.relative(projectDirPath);
......
...@@ -311,6 +311,7 @@ abstract class CreateBase extends FlutterCommand { ...@@ -311,6 +311,7 @@ abstract class CreateBase extends FlutterCommand {
String androidLanguage, String androidLanguage,
String iosLanguage, String iosLanguage,
String flutterRoot, String flutterRoot,
String dartSdkVersionBounds,
bool withPluginHook = false, bool withPluginHook = false,
bool ios = false, bool ios = false,
bool android = false, bool android = false,
...@@ -364,6 +365,7 @@ abstract class CreateBase extends FlutterCommand { ...@@ -364,6 +365,7 @@ abstract class CreateBase extends FlutterCommand {
'macos': macos, 'macos': macos,
'windows': windows, 'windows': windows,
'year': DateTime.now().year, 'year': DateTime.now().year,
'dartSdkVersionBounds': dartSdkVersionBounds,
}; };
} }
......
...@@ -20,7 +20,7 @@ version: 1.0.0+1 ...@@ -20,7 +20,7 @@ version: 1.0.0+1
{{/withPluginHook}} {{/withPluginHook}}
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: {{dartSdkVersionBounds}}
dependencies: dependencies:
flutter: flutter:
......
...@@ -18,7 +18,7 @@ description: {{description}} ...@@ -18,7 +18,7 @@ description: {{description}}
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.1.0 <3.0.0" sdk: {{dartSdkVersionBounds}}
dependencies: dependencies:
flutter: flutter:
......
...@@ -5,7 +5,7 @@ author: ...@@ -5,7 +5,7 @@ author:
homepage: homepage:
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: {{dartSdkVersionBounds}}
flutter: ">=1.17.0" flutter: ">=1.17.0"
dependencies: dependencies:
......
...@@ -1602,6 +1602,20 @@ void main() { ...@@ -1602,6 +1602,20 @@ void main() {
HttpClientFactory: () => () => MockHttpClient(200, result: 'void main() {}'), HttpClientFactory: () => () => MockHttpClient(200, result: 'void main() {}'),
}); });
testUsingContext('null-safe sample-based project have no analyzer errors', () async {
await _createAndAnalyzeProject(
projectDir,
<String>['--no-pub', '--sample=foo.bar.Baz'],
<String>['lib/main.dart'],
);
expect(
projectDir.childDirectory('lib').childFile('main.dart').readAsStringSync(),
contains('String?'), // uses null-safe syntax
);
}, overrides: <Type, Generator>{
HttpClientFactory: () => () => MockHttpClient(200, result: 'void main() { String? foo; print(foo); }'),
});
testUsingContext('can write samples index to disk', () async { testUsingContext('can write samples index to disk', () async {
final String outputFile = globals.fs.path.join(tempDir.path, 'flutter_samples.json'); final String outputFile = globals.fs.path.join(tempDir.path, 'flutter_samples.json');
final CreateCommand command = CreateCommand(); final CreateCommand command = CreateCommand();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment