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

This commit is contained in:
Michael Goderbauer 2021-01-27 14:44:03 -08:00 committed by GitHub
parent d11fe85676
commit 63267e9016
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 3 deletions

View File

@ -236,6 +236,8 @@ class CreateCommand extends CreateBase {
linux: featureFlags.isLinuxEnabled && platforms.contains('linux'),
macos: featureFlags.isMacOSEnabled && platforms.contains('macos'),
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);

View File

@ -311,6 +311,7 @@ abstract class CreateBase extends FlutterCommand {
String androidLanguage,
String iosLanguage,
String flutterRoot,
String dartSdkVersionBounds,
bool withPluginHook = false,
bool ios = false,
bool android = false,
@ -364,6 +365,7 @@ abstract class CreateBase extends FlutterCommand {
'macos': macos,
'windows': windows,
'year': DateTime.now().year,
'dartSdkVersionBounds': dartSdkVersionBounds,
};
}

View File

@ -20,7 +20,7 @@ version: 1.0.0+1
{{/withPluginHook}}
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: {{dartSdkVersionBounds}}
dependencies:
flutter:

View File

@ -18,7 +18,7 @@ description: {{description}}
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
sdk: {{dartSdkVersionBounds}}
dependencies:
flutter:

View File

@ -5,7 +5,7 @@ author:
homepage:
environment:
sdk: ">=2.7.0 <3.0.0"
sdk: {{dartSdkVersionBounds}}
flutter: ">=1.17.0"
dependencies:

View File

@ -1602,6 +1602,20 @@ 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 {
final String outputFile = globals.fs.path.join(tempDir.path, 'flutter_samples.json');
final CreateCommand command = CreateCommand();