mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Migrate the first batch of API samples to null safety (#72169)
This commit is contained in:
parent
fb3dba74b7
commit
c9cb43ce1a
@ -8,7 +8,6 @@
|
|||||||
// bin/cache/dart-sdk/bin/dart dev/bots/analyze-sample-code.dart
|
// bin/cache/dart-sdk/bin/dart dev/bots/analyze-sample-code.dart
|
||||||
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:isolate';
|
|
||||||
|
|
||||||
import 'package:args/args.dart';
|
import 'package:args/args.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
@ -203,6 +202,8 @@ class SampleChecker {
|
|||||||
return _headers ??= <String>[
|
return _headers ??= <String>[
|
||||||
'// generated code',
|
'// generated code',
|
||||||
'// ignore_for_file: unused_import',
|
'// ignore_for_file: unused_import',
|
||||||
|
'// ignore_for_file: unused_element',
|
||||||
|
'// ignore_for_file: unused_local_variable',
|
||||||
"import 'dart:async';",
|
"import 'dart:async';",
|
||||||
"import 'dart:convert';",
|
"import 'dart:convert';",
|
||||||
"import 'dart:math' as math;",
|
"import 'dart:math' as math;",
|
||||||
@ -547,8 +548,9 @@ linter:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Invokes the analyzer on the given [directory] and returns the stdout.
|
/// Invokes the analyzer on the given [directory] and returns the stdout.
|
||||||
List<String> _runAnalyzer(Directory directory) {
|
List<String> _runAnalyzer(Directory directory, {bool silent}) {
|
||||||
print('Starting analysis of code samples.');
|
if (!silent)
|
||||||
|
print('Starting analysis of code samples.');
|
||||||
_createConfigurationFiles(directory);
|
_createConfigurationFiles(directory);
|
||||||
final ProcessResult result = Process.runSync(
|
final ProcessResult result = Process.runSync(
|
||||||
_flutter,
|
_flutter,
|
||||||
@ -570,7 +572,7 @@ linter:
|
|||||||
stderr.removeLast();
|
stderr.removeLast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stderr.isNotEmpty) {
|
if (stderr.isNotEmpty && stderr.any((String line) => line.isNotEmpty)) {
|
||||||
throw 'Cannot analyze dartdocs; unexpected error output:\n$stderr';
|
throw 'Cannot analyze dartdocs; unexpected error output:\n$stderr';
|
||||||
}
|
}
|
||||||
if (stdout.isNotEmpty && stdout.first == 'Building flutter tool...') {
|
if (stdout.isNotEmpty && stdout.first == 'Building flutter tool...') {
|
||||||
@ -588,9 +590,10 @@ linter:
|
|||||||
Map<String, List<AnalysisError>> _analyze(
|
Map<String, List<AnalysisError>> _analyze(
|
||||||
Directory directory,
|
Directory directory,
|
||||||
Map<String, Section> sections,
|
Map<String, Section> sections,
|
||||||
Map<String, Sample> samples,
|
Map<String, Sample> samples, {
|
||||||
) {
|
bool silent = false,
|
||||||
final List<String> errors = _runAnalyzer(directory);
|
}) {
|
||||||
|
final List<String> errors = _runAnalyzer(directory, silent: silent);
|
||||||
final Map<String, List<AnalysisError>> analysisErrors = <String, List<AnalysisError>>{};
|
final Map<String, List<AnalysisError>> analysisErrors = <String, List<AnalysisError>>{};
|
||||||
void addAnalysisError(File file, AnalysisError error) {
|
void addAnalysisError(File file, AnalysisError error) {
|
||||||
if (analysisErrors.containsKey(file.path)) {
|
if (analysisErrors.containsKey(file.path)) {
|
||||||
@ -621,10 +624,6 @@ linter:
|
|||||||
final String errorCode = parts[6];
|
final String errorCode = parts[6];
|
||||||
final int lineNumber = int.parse(line, radix: 10) - (isSnippet ? headerLength : 0);
|
final int lineNumber = int.parse(line, radix: 10) - (isSnippet ? headerLength : 0);
|
||||||
final int columnNumber = int.parse(column, radix: 10);
|
final int columnNumber = int.parse(column, radix: 10);
|
||||||
if (lineNumber < 0 && errorCode == 'unused_import') {
|
|
||||||
// We don't care about unused imports.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For when errors occur outside of the things we're trying to analyze.
|
// For when errors occur outside of the things we're trying to analyze.
|
||||||
if (!isSnippet && !isSample) {
|
if (!isSnippet && !isSample) {
|
||||||
@ -649,10 +648,6 @@ linter:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorCode == 'unused_element' || errorCode == 'unused_local_variable') {
|
|
||||||
// We don't really care if sample code isn't used!
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (isSample) {
|
if (isSample) {
|
||||||
addAnalysisError(
|
addAnalysisError(
|
||||||
file,
|
file,
|
||||||
@ -739,7 +734,8 @@ linter:
|
|||||||
_exitCode = 0;
|
_exitCode = 0;
|
||||||
}
|
}
|
||||||
if (_exitCode == 0) {
|
if (_exitCode == 0) {
|
||||||
print('No analysis errors in samples!');
|
if (!silent)
|
||||||
|
print('No analysis errors in samples!');
|
||||||
assert(analysisErrors.isEmpty);
|
assert(analysisErrors.isEmpty);
|
||||||
}
|
}
|
||||||
return analysisErrors;
|
return analysisErrors;
|
||||||
@ -960,24 +956,28 @@ Future<void> _runInteractive(Directory tempDir, Directory flutterPackage, String
|
|||||||
print('Using temp dir ${tempDir.path}');
|
print('Using temp dir ${tempDir.path}');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void analyze(SampleChecker checker, File file) {
|
||||||
|
final Map<String, Section> sections = <String, Section>{};
|
||||||
|
final Map<String, Sample> snippets = <String, Sample>{};
|
||||||
|
checker._extractSamples(<File>[file], silent: true, sectionMap: sections, sampleMap: snippets);
|
||||||
|
final Map<String, List<AnalysisError>> errors = checker._analyze(checker._tempDirectory, sections, snippets, silent: true);
|
||||||
|
stderr.writeln('\u001B[2J\u001B[H'); // Clears the old results from the terminal.
|
||||||
|
if (errors.isNotEmpty) {
|
||||||
|
for (final String filePath in errors.keys) {
|
||||||
|
errors[filePath].forEach(stderr.writeln);
|
||||||
|
}
|
||||||
|
stderr.writeln('\nFound ${errors.length} errors.');
|
||||||
|
} else {
|
||||||
|
stderr.writeln('\nNo issues found.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final SampleChecker checker = SampleChecker(flutterPackage, tempDirectory: tempDir)
|
final SampleChecker checker = SampleChecker(flutterPackage, tempDirectory: tempDir)
|
||||||
.._createConfigurationFiles(tempDir)
|
.._createConfigurationFiles(tempDir);
|
||||||
.._extractSamples(<File>[file], silent: true);
|
analyze(checker, file);
|
||||||
|
|
||||||
await Isolate.spawn(_watcher, <dynamic>[checker, file]);
|
|
||||||
|
|
||||||
await Process.start(
|
|
||||||
_flutter,
|
|
||||||
<String>['--no-wrap', 'analyze', '--no-preamble', '--no-congratulate', '--watch', '.'],
|
|
||||||
workingDirectory: tempDir.absolute.path,
|
|
||||||
mode: ProcessStartMode.inheritStdio
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _watcher(List<dynamic> args) {
|
|
||||||
final File file = args.last as File;
|
|
||||||
final SampleChecker checker = args.first as SampleChecker;
|
|
||||||
Watcher(file.absolute.path).events.listen((_) {
|
Watcher(file.absolute.path).events.listen((_) {
|
||||||
checker._extractSamples(<File>[file], silent: true);
|
print('\n\nRerunning...');
|
||||||
|
analyze(checker, file);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'tween.dart';
|
import 'tween.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
// late AnimationController _controller;
|
||||||
// AnimationController _controller;
|
|
||||||
|
|
||||||
/// The status of an animation.
|
/// The status of an animation.
|
||||||
enum AnimationStatus {
|
enum AnimationStatus {
|
||||||
|
@ -17,9 +17,8 @@ import 'listener_helpers.dart';
|
|||||||
export 'package:flutter/scheduler.dart' show TickerFuture, TickerCanceled;
|
export 'package:flutter/scheduler.dart' show TickerFuture, TickerCanceled;
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
// late AnimationController _controller, fadeAnimationController, sizeAnimationController;
|
||||||
// AnimationController _controller, fadeAnimationController, sizeAnimationController;
|
// late bool dismissed;
|
||||||
// bool dismissed;
|
|
||||||
// void setState(VoidCallback fn) { }
|
// void setState(VoidCallback fn) { }
|
||||||
|
|
||||||
/// The direction in which an animation is running.
|
/// The direction in which an animation is running.
|
||||||
@ -137,7 +136,7 @@ enum AnimationBehavior {
|
|||||||
///
|
///
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// class Foo extends StatefulWidget {
|
/// class Foo extends StatefulWidget {
|
||||||
/// Foo({ Key key, this.duration }) : super(key: key);
|
/// Foo({ Key? key, required this.duration }) : super(key: key);
|
||||||
///
|
///
|
||||||
/// final Duration duration;
|
/// final Duration duration;
|
||||||
///
|
///
|
||||||
@ -146,7 +145,7 @@ enum AnimationBehavior {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// class _FooState extends State<Foo> with SingleTickerProviderStateMixin {
|
/// class _FooState extends State<Foo> with SingleTickerProviderStateMixin {
|
||||||
/// AnimationController _controller;
|
/// late AnimationController _controller;
|
||||||
///
|
///
|
||||||
/// @override
|
/// @override
|
||||||
/// void initState() {
|
/// void initState() {
|
||||||
|
@ -12,8 +12,7 @@ import 'curves.dart';
|
|||||||
import 'listener_helpers.dart';
|
import 'listener_helpers.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
// late AnimationController controller;
|
||||||
// AnimationController controller;
|
|
||||||
|
|
||||||
class _AlwaysCompleteAnimation extends Animation<double> {
|
class _AlwaysCompleteAnimation extends Animation<double> {
|
||||||
const _AlwaysCompleteAnimation();
|
const _AlwaysCompleteAnimation();
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
|
||||||
import 'dart:ui' show Color, Size, Rect;
|
import 'dart:ui' show Color, Size, Rect;
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
@ -12,9 +11,8 @@ import 'animations.dart';
|
|||||||
import 'curves.dart';
|
import 'curves.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
// late Animation<Offset> _animation;
|
||||||
// Animation<Offset> _animation;
|
// late AnimationController _controller;
|
||||||
// AnimationController _controller;
|
|
||||||
|
|
||||||
/// An object that can produce a value of type `T` given an [Animation<double>]
|
/// An object that can produce a value of type `T` given an [Animation<double>]
|
||||||
/// as input.
|
/// as input.
|
||||||
|
@ -7,8 +7,7 @@ import 'animation.dart';
|
|||||||
import 'tween.dart';
|
import 'tween.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
// late AnimationController myAnimationController;
|
||||||
// AnimationController myAnimationController;
|
|
||||||
|
|
||||||
/// Enables creating an [Animation] whose value is defined by a sequence of
|
/// Enables creating an [Animation] whose value is defined by a sequence of
|
||||||
/// [Tween]s.
|
/// [Tween]s.
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
|
||||||
// class Cat { }
|
// class Cat { }
|
||||||
|
|
||||||
/// A category with which to annotate a class, for documentation
|
/// A category with which to annotate a class, for documentation
|
||||||
|
@ -11,11 +11,10 @@ import 'print.dart';
|
|||||||
import 'stack_frame.dart';
|
import 'stack_frame.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
// late String runtimeType;
|
||||||
// String runtimeType;
|
// late bool draconisAlive;
|
||||||
// bool draconisAlive;
|
// late bool draconisAmulet;
|
||||||
// bool draconisAmulet;
|
// late Diagnosticable draconis;
|
||||||
// Diagnosticable draconis;
|
|
||||||
|
|
||||||
/// Signature for [FlutterError.onError] handler.
|
/// Signature for [FlutterError.onError] handler.
|
||||||
typedef FlutterExceptionHandler = void Function(FlutterErrorDetails details);
|
typedef FlutterExceptionHandler = void Function(FlutterErrorDetails details);
|
||||||
|
@ -12,10 +12,9 @@ import 'debug.dart';
|
|||||||
import 'object.dart';
|
import 'object.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
// late int rows, columns;
|
||||||
// int rows, columns;
|
// late String _name;
|
||||||
// String _name;
|
// late bool inherit;
|
||||||
// bool inherit;
|
|
||||||
|
|
||||||
/// The various priority levels used to filter which diagnostics are shown and
|
/// The various priority levels used to filter which diagnostics are shown and
|
||||||
/// omitted.
|
/// omitted.
|
||||||
@ -3069,7 +3068,7 @@ class DiagnosticPropertiesBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// class ExampleSuperclass with Diagnosticable { String message; double stepWidth; double scale; double paintExtent; double hitTestExtent; double paintExtend; double maxWidth; bool primary; double progress; int maxLines; Duration duration; int depth; dynamic boxShadow; dynamic style; bool hasSize; Matrix4 transform; Map<Listenable, VoidCallback> handles; Color color; bool obscureText; ImageRepeat repeat; Size size; Widget widget; bool isCurrent; bool keepAlive; TextAlign textAlign; }
|
// class ExampleSuperclass with Diagnosticable { late String message; late double stepWidth; late double scale; late double paintExtent; late double hitTestExtent; late double paintExtend; late double maxWidth; late bool primary; late double progress; late int maxLines; late Duration duration; late int depth; late dynamic boxShadow; late dynamic style; late bool hasSize; late Matrix4 transform; Map<Listenable, VoidCallback>? handles; late Color color; late bool obscureText; late ImageRepeat repeat; late Size size; late Widget widget; late bool isCurrent; late bool keepAlive; late TextAlign textAlign; }
|
||||||
|
|
||||||
/// A mixin class for providing string and [DiagnosticsNode] debug
|
/// A mixin class for providing string and [DiagnosticsNode] debug
|
||||||
/// representations describing the properties of an object.
|
/// representations describing the properties of an object.
|
||||||
@ -3326,9 +3325,9 @@ mixin Diagnosticable {
|
|||||||
/// properties.add(DiagnosticsProperty<Map<Listenable, VoidCallback>>(
|
/// properties.add(DiagnosticsProperty<Map<Listenable, VoidCallback>>(
|
||||||
/// 'handles',
|
/// 'handles',
|
||||||
/// handles,
|
/// handles,
|
||||||
/// description: handles != null ?
|
/// description: handles != null
|
||||||
/// '${handles.length} active client${ handles.length == 1 ? "" : "s" }' :
|
/// ? '${handles!.length} active client${ handles!.length == 1 ? "" : "s" }'
|
||||||
/// null,
|
/// : null,
|
||||||
/// ifNull: 'no notifications ever received',
|
/// ifNull: 'no notifications ever received',
|
||||||
/// showName: false,
|
/// showName: false,
|
||||||
/// ));
|
/// ));
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:ui' as ui show lerpDouble;
|
import 'dart:ui' as ui show lerpDouble;
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
import 'basic_types.dart';
|
import 'basic_types.dart';
|
||||||
@ -11,8 +10,7 @@ import 'borders.dart';
|
|||||||
import 'edge_insets.dart';
|
import 'edge_insets.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// // @dart = 2.9
|
// late BuildContext context;
|
||||||
// BuildContext context;
|
|
||||||
|
|
||||||
/// The shape to use when rendering a [Border] or [BoxDecoration].
|
/// The shape to use when rendering a [Border] or [BoxDecoration].
|
||||||
///
|
///
|
||||||
|
@ -17,9 +17,6 @@ import 'binding.dart';
|
|||||||
import 'image_cache.dart';
|
import 'image_cache.dart';
|
||||||
import 'image_stream.dart';
|
import 'image_stream.dart';
|
||||||
|
|
||||||
// Examples can assume:
|
|
||||||
// // @dart = 2.9
|
|
||||||
|
|
||||||
/// Signature for the callback taken by [_createErrorHandlerAndKey].
|
/// Signature for the callback taken by [_createErrorHandlerAndKey].
|
||||||
typedef _KeyAndErrorHandlerCallback<T> = void Function(T key, ImageErrorListener handleError);
|
typedef _KeyAndErrorHandlerCallback<T> = void Function(T key, ImageErrorListener handleError);
|
||||||
|
|
||||||
@ -239,10 +236,9 @@ typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int? cache
|
|||||||
/// ```dart
|
/// ```dart
|
||||||
/// class MyImage extends StatefulWidget {
|
/// class MyImage extends StatefulWidget {
|
||||||
/// const MyImage({
|
/// const MyImage({
|
||||||
/// Key key,
|
/// Key? key,
|
||||||
/// @required this.imageProvider,
|
/// required this.imageProvider,
|
||||||
/// }) : assert(imageProvider != null),
|
/// }) : super(key: key);
|
||||||
/// super(key: key);
|
|
||||||
///
|
///
|
||||||
/// final ImageProvider imageProvider;
|
/// final ImageProvider imageProvider;
|
||||||
///
|
///
|
||||||
@ -251,8 +247,8 @@ typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int? cache
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// class _MyImageState extends State<MyImage> {
|
/// class _MyImageState extends State<MyImage> {
|
||||||
/// ImageStream _imageStream;
|
/// ImageStream? _imageStream;
|
||||||
/// ImageInfo _imageInfo;
|
/// ImageInfo? _imageInfo;
|
||||||
///
|
///
|
||||||
/// @override
|
/// @override
|
||||||
/// void didChangeDependencies() {
|
/// void didChangeDependencies() {
|
||||||
@ -271,15 +267,15 @@ typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int? cache
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// void _getImage() {
|
/// void _getImage() {
|
||||||
/// final ImageStream oldImageStream = _imageStream;
|
/// final ImageStream? oldImageStream = _imageStream;
|
||||||
/// _imageStream = widget.imageProvider.resolve(createLocalImageConfiguration(context));
|
/// _imageStream = widget.imageProvider.resolve(createLocalImageConfiguration(context));
|
||||||
/// if (_imageStream.key != oldImageStream?.key) {
|
/// if (_imageStream!.key != oldImageStream?.key) {
|
||||||
/// // If the keys are the same, then we got the same image back, and so we don't
|
/// // If the keys are the same, then we got the same image back, and so we don't
|
||||||
/// // need to update the listeners. If the key changed, though, we must make sure
|
/// // need to update the listeners. If the key changed, though, we must make sure
|
||||||
/// // to switch our listeners to the new image stream.
|
/// // to switch our listeners to the new image stream.
|
||||||
/// final ImageStreamListener listener = ImageStreamListener(_updateImage);
|
/// final ImageStreamListener listener = ImageStreamListener(_updateImage);
|
||||||
/// oldImageStream?.removeListener(listener);
|
/// oldImageStream?.removeListener(listener);
|
||||||
/// _imageStream.addListener(listener);
|
/// _imageStream!.addListener(listener);
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
@ -293,7 +289,7 @@ typedef DecoderCallback = Future<ui.Codec> Function(Uint8List bytes, {int? cache
|
|||||||
///
|
///
|
||||||
/// @override
|
/// @override
|
||||||
/// void dispose() {
|
/// void dispose() {
|
||||||
/// _imageStream.removeListener(ImageStreamListener(_updateImage));
|
/// _imageStream?.removeListener(ImageStreamListener(_updateImage));
|
||||||
/// _imageInfo?.dispose();
|
/// _imageInfo?.dispose();
|
||||||
/// _imageInfo = null;
|
/// _imageInfo = null;
|
||||||
/// super.dispose();
|
/// super.dispose();
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
Loading…
Reference in New Issue
Block a user