Enable strict-inference (#135043)

Avoids that dynamic accidentally sneaks in, see https://dart.dev/tools/analysis#enabling-additional-type-checks
This commit is contained in:
Michael Goderbauer
2023-09-20 12:59:08 -07:00
committed by GitHub
parent 96a4ae9dc5
commit b0a90aee17
27 changed files with 63 additions and 55 deletions

View File

@@ -111,7 +111,7 @@ mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin
/// build method - potentially after wrapping it in other widgets.
Widget buildToggleable({
FocusNode? focusNode,
Function(bool)? onFocusChange,
ValueChanged<bool>? onFocusChange,
bool autofocus = false,
required Size size,
required CustomPainter painter,

View File

@@ -440,7 +440,7 @@ class _DragHandle extends StatelessWidget {
});
final VoidCallback? onSemanticsTap;
final Function(bool) handleHover;
final ValueChanged<bool> handleHover;
final Set<MaterialState> materialState;
final Color? dragHandleColor;
final Size? dragHandleSize;

View File

@@ -710,7 +710,7 @@ class _MaterialSwitch extends StatefulWidget {
final MaterialStateProperty<Color?>? overlayColor;
final double? splashRadius;
final FocusNode? focusNode;
final Function(bool)? onFocusChange;
final ValueChanged<bool>? onFocusChange;
final bool autofocus;
final Size size;

View File

@@ -302,7 +302,7 @@ mixin ToggleableStateMixin<S extends StatefulWidget> on TickerProviderStateMixin
/// build method - potentially after wrapping it in other widgets.
Widget buildToggleable({
FocusNode? focusNode,
Function(bool)? onFocusChange,
ValueChanged<bool>? onFocusChange,
bool autofocus = false,
required MaterialStateProperty<MouseCursor> mouseCursor,
required Size size,

View File

@@ -5470,7 +5470,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
}
/// Gets first route entry satisfying the predicate, or null if not found.
_RouteEntry? _firstRouteEntryWhereOrNull<T>(_RouteEntryPredicate test) {
_RouteEntry? _firstRouteEntryWhereOrNull(_RouteEntryPredicate test) {
for (final _RouteEntry element in _history) {
if (test(element)) {
return element;
@@ -5480,7 +5480,7 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin, Res
}
/// Gets last route entry satisfying the predicate, or null if not found.
_RouteEntry? _lastRouteEntryWhereOrNull<T>(_RouteEntryPredicate test) {
_RouteEntry? _lastRouteEntryWhereOrNull(_RouteEntryPredicate test) {
_RouteEntry? result;
for (final _RouteEntry element in _history) {
if (test(element)) {

View File

@@ -3352,7 +3352,7 @@ void main() {
itemBuilder: (BuildContext context) => <PopupMenuItem<int>>[
PopupMenuItem<int>(
onTap: () {
showModalBottomSheet(
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return const SizedBox(

View File

@@ -464,7 +464,7 @@ void main() {
});
test('ColorSwatch.lerp identical a,b', () {
expect(ColorSwatch.lerp(null, null, 0), null);
expect(ColorSwatch.lerp<Object?>(null, null, 0), null);
const ColorSwatch<int> color = ColorSwatch<int>(0x00000000, <int, Color>{1: Color(0x00000000)});
expect(identical(ColorSwatch.lerp(color, color, 0.5), color), true);
});

View File

@@ -881,7 +881,7 @@ void main() {
});
// Simulate painting a RenderBox as if 'debugPaintSizeEnabled == true'
Function(PaintingContext, Offset) debugPaint(RenderBox renderBox) {
DebugPaintCallback debugPaint(RenderBox renderBox) {
layout(renderBox);
pumpFrame(phase: EnginePhase.compositingBits);
return (PaintingContext context, Offset offset) {
@@ -891,7 +891,7 @@ void main() {
}
test('RenderClipPath.debugPaintSize draws a path and a debug text when clipBehavior is not Clip.none', () {
Function(PaintingContext, Offset) debugPaintClipRect(Clip clip) {
DebugPaintCallback debugPaintClipRect(Clip clip) {
final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
final RenderClipPath renderClipPath = RenderClipPath(clipBehavior: clip, child: child);
return debugPaint(renderClipPath);
@@ -908,7 +908,7 @@ void main() {
});
test('RenderClipRect.debugPaintSize draws a rect and a debug text when clipBehavior is not Clip.none', () {
Function(PaintingContext, Offset) debugPaintClipRect(Clip clip) {
DebugPaintCallback debugPaintClipRect(Clip clip) {
final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
final RenderClipRect renderClipRect = RenderClipRect(clipBehavior: clip, child: child);
return debugPaint(renderClipRect);
@@ -924,7 +924,7 @@ void main() {
});
test('RenderClipRRect.debugPaintSize draws a rounded rect and a debug text when clipBehavior is not Clip.none', () {
Function(PaintingContext, Offset) debugPaintClipRRect(Clip clip) {
DebugPaintCallback debugPaintClipRRect(Clip clip) {
final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
final RenderClipRRect renderClipRRect = RenderClipRRect(clipBehavior: clip, child: child);
return debugPaint(renderClipRRect);
@@ -940,7 +940,7 @@ void main() {
});
test('RenderClipOval.debugPaintSize draws a path and a debug text when clipBehavior is not Clip.none', () {
Function(PaintingContext, Offset) debugPaintClipOval(Clip clip) {
DebugPaintCallback debugPaintClipOval(Clip clip) {
final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
final RenderClipOval renderClipOval = RenderClipOval(clipBehavior: clip, child: child);
return debugPaint(renderClipOval);
@@ -1085,3 +1085,5 @@ void expectAssertionError() {
FlutterError.reportError(errorDetails);
}
}
typedef DebugPaintCallback = void Function(PaintingContext context, Offset offset);

View File

@@ -11,7 +11,7 @@ import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
class _MediaQueryAspectCase {
const _MediaQueryAspectCase(this.method, this.data);
final Function(BuildContext) method;
final void Function(BuildContext) method;
final MediaQueryData data;
}

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -327,7 +328,7 @@ void main() {
testWidgets('Assertion error when SliverExpanded is used outside of SliverCrossAxisGroup', (WidgetTester tester) async {
final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[];
final Function(FlutterErrorDetails)? oldHandler = FlutterError.onError;
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails error) => errors.add(error);
await tester.pumpWidget(
@@ -459,7 +460,7 @@ void main() {
testWidgetsWithLeakTracking('Assertion error when constrained widget runs out of cross axis extent', (WidgetTester tester) async {
final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[];
final Function(FlutterErrorDetails)? oldHandler = FlutterError.onError;
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails error) => errors.add(error);
final List<int> items = List<int>.generate(20, (int i) => i);
@@ -481,7 +482,7 @@ void main() {
testWidgetsWithLeakTracking('Assertion error when expanded widget runs out of cross axis extent', (WidgetTester tester) async {
final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[];
final Function(FlutterErrorDetails)? oldHandler = FlutterError.onError;
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails error) => errors.add(error);
final List<int> items = List<int>.generate(20, (int i) => i);

View File

@@ -128,7 +128,7 @@ class _MockHttpClient implements HttpClient {
bool Function(X509Certificate cert, String host, int port)? badCertificateCallback;
@override
Function(String line)? keyLog;
void Function(String line)? keyLog;
@override
void close({ bool force = false }) { }

View File

@@ -19,7 +19,7 @@ void verifyPropertyFaked<TProperty>({
required TProperty realValue,
required TProperty fakeValue,
required TProperty Function() propertyRetriever,
required Function(TestWidgetsFlutterBinding, TProperty fakeValue) propertyFaker,
required void Function(TestWidgetsFlutterBinding, TProperty fakeValue) propertyFaker,
Matcher Function(TProperty) matcher = equals,
}) {
TProperty propertyBeforeFaking;
@@ -45,8 +45,8 @@ void verifyPropertyReset<TProperty>({
required WidgetTester tester,
required TProperty fakeValue,
required TProperty Function() propertyRetriever,
required Function() propertyResetter,
required Function(TProperty fakeValue) propertyFaker,
required VoidCallback propertyResetter,
required ValueSetter<TProperty> propertyFaker,
Matcher Function(TProperty) matcher = equals,
}) {
TProperty propertyBeforeFaking;

View File

@@ -80,7 +80,7 @@ void main () {
expect(iosDeployDebugger.logLines, emits('Did finish launching.'));
expect(await iosDeployDebugger.launchAndAttach(), isTrue);
await iosDeployDebugger.logLines.drain();
await iosDeployDebugger.logLines.drain<Object?>();
expect(processManager, hasNoRemainingExpectations);
expect(appDeltaDirectory, exists);
});
@@ -141,7 +141,7 @@ void main () {
'process detach',
]));
expect(await iosDeployDebugger.launchAndAttach(), isTrue);
await logLines.drain();
await logLines.drain<Object?>();
expect(logger.traceText, contains('PROCESS_STOPPED'));
expect(logger.traceText, contains('thread backtrace all'));
@@ -189,7 +189,7 @@ void main () {
expect(iosDeployDebugger.logLines, emitsDone);
expect(await iosDeployDebugger.launchAndAttach(), isFalse);
await iosDeployDebugger.logLines.drain();
await iosDeployDebugger.logLines.drain<Object?>();
});
testWithoutContext('app exit', () async {
@@ -209,7 +209,7 @@ void main () {
]));
expect(await iosDeployDebugger.launchAndAttach(), isTrue);
await iosDeployDebugger.logLines.drain();
await iosDeployDebugger.logLines.drain<Object?>();
});
testWithoutContext('app crash', () async {
@@ -239,7 +239,7 @@ void main () {
]));
expect(await iosDeployDebugger.launchAndAttach(), isTrue);
await iosDeployDebugger.logLines.drain();
await iosDeployDebugger.logLines.drain<Object?>();
expect(logger.traceText, contains('Process 6156 stopped'));
expect(logger.traceText, contains('thread backtrace all'));
@@ -263,7 +263,7 @@ void main () {
expect(iosDeployDebugger.logLines, emitsDone);
expect(await iosDeployDebugger.launchAndAttach(), isFalse);
await iosDeployDebugger.logLines.drain();
await iosDeployDebugger.logLines.drain<Object?>();
});
testWithoutContext('no provisioning profile 1, stdout', () async {
@@ -364,7 +364,7 @@ void main () {
'Log on attach2',
]));
expect(await iosDeployDebugger.launchAndAttach(), isTrue);
await logLines.drain();
await logLines.drain<Object?>();
expect(LineSplitter.split(logger.traceText), containsOnce('Received logs from ios-deploy.'));
});

View File

@@ -19,7 +19,7 @@ abstract class DapTestServer {
Future<void> stop();
StreamSink<List<int>> get sink;
Stream<List<int>> get stream;
Function(String message)? onStderrOutput;
void Function(String message)? onStderrOutput;
}
/// An instance of a DAP server running in-process (to aid debugging).
@@ -83,7 +83,7 @@ class OutOfProcessDapTestServer extends DapTestServer {
.listen((String error) {
logger?.call(error);
if (!_isShuttingDown) {
final Function(String message)? stderrHandler = onStderrOutput;
final void Function(String message)? stderrHandler = onStderrOutput;
if (stderrHandler != null) {
stderrHandler(error);
} else {

View File

@@ -147,7 +147,7 @@ class FakeHttpClient implements HttpClient {
bool Function(X509Certificate cert, String host, int port)? badCertificateCallback;
@override
Function(String line)? keyLog;
void Function(String line)? keyLog;
@override
void close({bool force = false}) { }