more UI-as-code (#35516)

This commit is contained in:
Alexandre Ardhuin
2019-09-17 16:23:44 +02:00
committed by GitHub
parent d03aecab58
commit df4bf453ab
117 changed files with 1728 additions and 2132 deletions

View File

@@ -208,23 +208,20 @@ class SampleChecker {
/// Computes the headers needed for each sample file.
List<Line> get headers {
if (_headers == null) {
final List<String> buffer = <String>[];
buffer.add('// generated code');
buffer.add('import \'dart:async\';');
buffer.add('import \'dart:convert\';');
buffer.add('import \'dart:math\' as math;');
buffer.add('import \'dart:typed_data\';');
buffer.add('import \'dart:ui\' as ui;');
buffer.add('import \'package:flutter_test/flutter_test.dart\';');
for (File file in _listDartFiles(Directory(_defaultFlutterPackage))) {
buffer.add('');
buffer.add('// ${file.path}');
buffer.add('import \'package:flutter/${path.basename(file.path)}\';');
}
_headers = buffer.map<Line>((String code) => Line(code)).toList();
}
return _headers;
return _headers ??= <String>[
'// generated code',
"import 'dart:async';",
"import 'dart:convert';",
"import 'dart:math' as math;",
"import 'dart:typed_data';",
"import 'dart:ui' as ui;",
"import 'package:flutter_test/flutter_test.dart';",
for (File file in _listDartFiles(Directory(_defaultFlutterPackage))) ...<String>[
'',
'// ${file.path}',
"import 'package:flutter/${path.basename(file.path)}';",
],
].map<Line>((String code) => Line(code)).toList();
}
List<Line> _headers;

View File

@@ -177,7 +177,7 @@ Future<void> _checkForTrailingSpaces() async {
'*.dart', '*.cxx', '*.cpp', '*.cc', '*.c', '*.C', '*.h', '*.java', '*.mm', '*.m', '*.yml',
];
final EvalResult changedFilesResult = await _evalCommand(
'git', <String>['diff', '-U0', '--no-color', '--name-only', commitRange, '--'] + fileTypes,
'git', <String>['diff', '-U0', '--no-color', '--name-only', commitRange, '--', ...fileTypes],
workingDirectory: flutterRoot,
);
if (changedFilesResult.stdout == null || changedFilesResult.stdout.trim().isEmpty) {
@@ -195,7 +195,8 @@ Future<void> _checkForTrailingSpaces() async {
'--line-number',
'--extended-regexp',
r'[[:blank:]]$',
] + changedFiles,
...changedFiles,
],
workingDirectory: flutterRoot,
failureMessage: '${red}Whitespace detected at the end of source code lines.$reset\nPlease remove:',
expectNonZeroExit: true, // Just means a non-zero exit code is expected.

View File

@@ -527,20 +527,16 @@ class ArchivePublisher {
// Search for any entries with the same hash and channel and remove them.
final List<dynamic> releases = jsonData['releases'];
final List<Map<String, dynamic>> prunedReleases = <Map<String, dynamic>>[];
for (Map<String, dynamic> entry in releases) {
if (entry['hash'] != newEntry['hash'] || entry['channel'] != newEntry['channel']) {
prunedReleases.add(entry);
}
}
prunedReleases.add(newEntry);
prunedReleases.sort((Map<String, dynamic> a, Map<String, dynamic> b) {
jsonData['releases'] = <Map<String, dynamic>>[
for (Map<String, dynamic> entry in releases)
if (entry['hash'] != newEntry['hash'] || entry['channel'] != newEntry['channel'])
entry,
newEntry,
]..sort((Map<String, dynamic> a, Map<String, dynamic> b) {
final DateTime aDate = DateTime.parse(a['release_date']);
final DateTime bDate = DateTime.parse(b['release_date']);
return bDate.compareTo(aDate);
});
jsonData['releases'] = prunedReleases;
return jsonData;
}

View File

@@ -184,17 +184,16 @@ Future<bq.BigqueryApi> _getBigqueryApi() async {
// Partition tool tests into two groups, see explanation on `_runToolCoverage`.
List<List<String>> _partitionToolTests() {
final List<String> pending = <String>[];
final String toolTestDir = path.join(toolRoot, 'test');
for (FileSystemEntity entity in Directory(toolTestDir).listSync(recursive: true)) {
if (entity is File && entity.path.endsWith('_test.dart')) {
final String relativePath = path.relative(entity.path, from: toolRoot);
pending.add(relativePath);
}
}
final List<String> pending = <String>[
for (FileSystemEntity entity in Directory(toolTestDir).listSync(recursive: true))
if (entity is File && entity.path.endsWith('_test.dart'))
path.relative(entity.path, from: toolRoot),
];
// Shuffle the tests to avoid giving an expensive test directory like
// integration to a single run of tests.
pending..shuffle();
pending.shuffle();
final int aboutHalf = pending.length ~/ 2;
final List<String> groupA = pending.take(aboutHalf).toList();
final List<String> groupB = pending.skip(aboutHalf).toList();
@@ -512,19 +511,20 @@ Future<void> _buildRunnerTest(
bool enableFlutterToolAsserts = false,
bq.TabledataResourceApi tableData,
}) async {
final List<String> args = <String>['run', 'build_runner', 'test', '--', useFlutterTestFormatter ? '-rjson' : '-rcompact', '-j1'];
if (!hasColor) {
args.add('--no-color');
}
if (testPath != null) {
args.add(testPath);
}
final List<String> args = <String>[
'run',
'build_runner',
'test',
'--',
if (useFlutterTestFormatter) '-rjson' else '-rcompact',
'-j1',
if (!hasColor) '--no-color',
if (testPath != null) testPath,
];
final Map<String, String> pubEnvironment = <String, String>{
'FLUTTER_ROOT': flutterRoot,
if (Directory(pubCache).existsSync()) 'PUB_CACHE': pubCache,
};
if (Directory(pubCache).existsSync()) {
pubEnvironment['PUB_CACHE'] = pubCache;
}
if (enableFlutterToolAsserts) {
// If an existing env variable exists append to it, but only if
// it doesn't appear to already include enable-asserts.
@@ -574,15 +574,17 @@ Future<void> _pubRunTest(
bool enableFlutterToolAsserts = false,
bq.TabledataResourceApi tableData,
}) async {
final List<String> args = <String>['run', 'test', useFlutterTestFormatter ? '-rjson' : '-rcompact', '-j1'];
if (!hasColor)
args.add('--no-color');
if (testPath != null)
args.add(testPath);
final Map<String, String> pubEnvironment = <String, String>{};
if (Directory(pubCache).existsSync()) {
pubEnvironment['PUB_CACHE'] = pubCache;
}
final List<String> args = <String>[
'run',
'test',
if (useFlutterTestFormatter) '-rjson' else '-rcompact',
'-j1',
if (!hasColor) '--no-color',
if (testPath != null) testPath,
];
final Map<String, String> pubEnvironment = <String, String>{
if (Directory(pubCache).existsSync()) 'PUB_CACHE': pubCache,
};
if (enableFlutterToolAsserts) {
// If an existing env variable exists append to it, but only if
// it doesn't appear to already include enable-asserts.

View File

@@ -71,7 +71,7 @@ Future<Process> _run({@required Device device, @required List<String> command, @
await inDirectory(appDir, () async {
runner = await startProcess(
path.join(flutterDirectory.path, 'bin', 'flutter'),
<String>['--suppress-analytics', '-d', device.deviceId] + command,
<String>['--suppress-analytics', '-d', device.deviceId, ...command],
isBot: false, // we just want to test the output, not have any debugging info
);
final StreamController<String> stdout = StreamController<String>.broadcast();

View File

@@ -82,12 +82,11 @@ Future<Map<String, dynamic>> runTask(
}
Future<VMIsolateRef> _connectToRunnerIsolate(Uri vmServiceUri) async {
final List<String> pathSegments = <String>[];
if (vmServiceUri.pathSegments.isNotEmpty) {
final List<String> pathSegments = <String>[
// Add authentication code.
pathSegments.add(vmServiceUri.pathSegments[0]);
}
pathSegments.add('ws');
if (vmServiceUri.pathSegments.isNotEmpty) vmServiceUri.pathSegments[0],
'ws',
];
final String url = vmServiceUri.replace(scheme: 'ws', pathSegments:
pathSegments).toString();
final Stopwatch stopwatch = Stopwatch()..start();

View File

@@ -65,12 +65,10 @@ abstract class _Benchmark {
Directory get directory;
List<String> get options {
final List<String> result = <String>[ '--benchmark' ];
if (watch)
result.add('--watch');
return result;
}
List<String> get options => <String>[
'--benchmark',
if (watch) '--watch',
];
Future<double> execute(int iteration, int targetIterations) async {
section('Analyze $title ${watch ? 'with watcher' : ''} - ${iteration + 1} / $targetIterations');

View File

@@ -119,13 +119,11 @@ Future<void> saveCatalogScreenshots({
String token, // Cloud storage authorization token.
String prefix, // Prefix for all file names.
}) async {
final List<String> screenshots = <String>[];
for (FileSystemEntity entity in directory.listSync()) {
if (entity is File && entity.path.endsWith('.png')) {
final File file = entity;
screenshots.add(file.path);
}
}
final List<String> screenshots = <String>[
for (FileSystemEntity entity in directory.listSync())
if (entity is File && entity.path.endsWith('.png'))
entity.path,
];
final List<String> largeNames = <String>[]; // Cloud storage names for the full res screenshots.
final List<String> smallNames = <String>[]; // Likewise for the scaled down screenshots.

View File

@@ -144,13 +144,9 @@ class AndroidSemanticsNode {
}
/// Gets a list of [AndroidSemanticsActions] which are defined for the node.
List<AndroidSemanticsAction> getActions() {
final List<AndroidSemanticsAction> result = <AndroidSemanticsAction>[];
for (int id in _values['actions']) {
result.add(AndroidSemanticsAction.deserialize(id));
}
return result;
}
List<AndroidSemanticsAction> getActions() => <AndroidSemanticsAction>[
for (int id in _values['actions']) AndroidSemanticsAction.deserialize(id),
];
@override
String toString() {

View File

@@ -34,7 +34,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
});
},
),
_pressed ? GeneratedWidget() : const SizedBox(),
if (_pressed) GeneratedWidget() else const SizedBox(),
],
),
),

View File

@@ -3,7 +3,7 @@ description: A test of Flutter integrating code generation.
environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.2.2 <3.0.0"
dependencies:
flutter:

View File

@@ -179,26 +179,27 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
@override
Widget build(BuildContext context) {
final List<Widget> layers = <Widget>[
Scaffold(
appBar: AppBar(title: const Text('Tap a Card')),
body: Container(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 8.0),
child: NotificationListener<ScrollNotification>(
onNotification: handleScrollNotification,
child: ListView.custom(
childrenDelegate: CardBuilder(
cardModels: cardModels,
onTapUp: handleTapUp,
return Stack(
children: <Widget>[
Scaffold(
appBar: AppBar(title: const Text('Tap a Card')),
body: Container(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 8.0),
child: NotificationListener<ScrollNotification>(
onNotification: handleScrollNotification,
child: ListView.custom(
childrenDelegate: CardBuilder(
cardModels: cardModels,
onTapUp: handleTapUp,
),
),
),
),
),
),
];
for (MarkerType type in markers.keys)
layers.add(Marker(type: type, position: markers[type]));
return Stack(children: layers);
for (MarkerType type in markers.keys)
Marker(type: type, position: markers[type]),
],
);
}
}

View File

@@ -556,9 +556,6 @@ class _UnderlinesState extends State<Underlines> {
@override
Widget build(BuildContext context) {
final List<Widget> lines = <Widget>[_wrap(null)];
for (TextDecorationStyle style in TextDecorationStyle.values)
lines.add(_wrap(style));
final Size size = MediaQuery.of(context).size;
return Container(
color: Colors.black,
@@ -572,7 +569,10 @@ class _UnderlinesState extends State<Underlines> {
vertical: size.height * 0.1,
),
child: ListBody(
children: lines,
children: <Widget>[
_wrap(null),
for (TextDecorationStyle style in TextDecorationStyle.values) _wrap(style),
],
),
),
),
@@ -647,9 +647,6 @@ class _FallbackState extends State<Fallback> {
@override
Widget build(BuildContext context) {
final List<Widget> lines = <Widget>[];
for (String font in androidFonts)
lines.add(Text(multiScript, style: style.copyWith(fontFamily: font, fontSize: math.exp(_fontSize))));
final Size size = MediaQuery.of(context).size;
return Container(
color: Colors.black,
@@ -666,7 +663,16 @@ class _FallbackState extends State<Fallback> {
),
child: IntrinsicWidth(
child: ListBody(
children: lines,
children: <Widget>[
for (String font in androidFonts)
Text(
multiScript,
style: style.copyWith(
fontFamily: font,
fontSize: math.exp(_fontSize),
),
),
],
),
),
),

View File

@@ -2,7 +2,7 @@ name: manual_tests
environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.2.0 <3.0.0"
sdk: ">=2.2.2 <3.0.0"
dependencies:
flutter:

View File

@@ -108,11 +108,12 @@ Future<void> main(List<String> arguments) async {
createSearchMetadata('$kDocsRoot/lib/opensearch.xml', '$kDocsRoot/doc/opensearch.xml');
cleanOutSnippets();
final List<String> dartdocBaseArgs = <String>['global', 'run'];
if (args['checked']) {
dartdocBaseArgs.add('-c');
}
dartdocBaseArgs.add('dartdoc');
final List<String> dartdocBaseArgs = <String>[
'global',
'run',
if (args['checked']) '-c',
'dartdoc',
];
// Verify which version of dartdoc we're using.
final ProcessResult result = Process.runSync(
@@ -123,24 +124,17 @@ Future<void> main(List<String> arguments) async {
);
print('\n${result.stdout}flutter version: $version\n');
dartdocBaseArgs.add('--allow-tools');
if (args['json']) {
dartdocBaseArgs.add('--json');
}
if (args['validate-links']) {
dartdocBaseArgs.add('--validate-links');
} else {
dartdocBaseArgs.add('--no-validate-links');
}
dartdocBaseArgs.addAll(<String>['--link-to-source-excludes', '../../bin/cache',
'--link-to-source-root', '../..',
'--link-to-source-uri-template', 'https://github.com/flutter/flutter/blob/master/%f%#L%l%']);
// Generate the documentation.
// We don't need to exclude flutter_tools in this list because it's not in the
// recursive dependencies of the package defined at dev/docs/pubspec.yaml
final List<String> dartdocArgs = <String>[
...dartdocBaseArgs,
'--allow-tools',
if (args['json']) '--json',
if (args['validate-links']) '--validate-links' else '--no-validate-links',
'--link-to-source-excludes', '../../bin/cache',
'--link-to-source-root', '../..',
'--link-to-source-uri-template', 'https://github.com/flutter/flutter/blob/master/%f%#L%l%',
'--inject-html',
'--header', 'styles.html',
'--header', 'analytics.html',

View File

@@ -52,10 +52,9 @@ class KeyData {
/// Parses the given JSON data and populates the data structure from it.
KeyData.fromJson(Map<String, dynamic> contentMap) {
data = <Key>[];
for (String key in contentMap.keys) {
data.add(Key.fromJsonMapEntry(key, contentMap[key]));
}
data = <Key>[
for (String key in contentMap.keys) Key.fromJsonMapEntry(key, contentMap[key]),
];
}
/// Converts the data structure into a JSON structure that can be parsed by

View File

@@ -3,7 +3,7 @@ description: Generates keycode source files from various resources.
environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.2.2 <3.0.0"
dependencies:
args: 1.5.2

View File

@@ -64,11 +64,9 @@ void main(List<String> args) {
return;
}
final List<FrameData> frames = <FrameData>[];
for (String filePath in argResults.rest) {
final FrameData data = interpretSvg(filePath);
frames.add(data);
}
final List<FrameData> frames = <FrameData>[
for (String filePath in argResults.rest) interpretSvg(filePath),
];
final StringBuffer generatedSb = StringBuffer();

View File

@@ -6,7 +6,7 @@ author: Flutter Authors <flutter-dev@googlegroups.com>
environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.2.2 <3.0.0"
dependencies:
args: 1.5.2