Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 19dfde6

Browse files
authored
Remove unnecessary null checks in flutter/{foundation,services,physics} (#118910)
* Remove unnecessary null checks in flutter/foundation * Remove unnecessary null checks in flutter/services * Remove unnecessary null checks in flutter/physics
1 parent a63e19b commit 19dfde6

34 files changed

+77
-348
lines changed

packages/flutter/lib/src/foundation/annotations.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
/// class that overrides the inline documentations' own description.
4040
class Category {
4141
/// Create an annotation to provide a categorization of a class.
42-
const Category(this.sections) : assert(sections != null);
42+
const Category(this.sections);
4343

4444
/// The strings the correspond to the section and subsection of the
4545
/// category represented by this object.
@@ -74,7 +74,7 @@ class Category {
7474
/// class that overrides the inline documentations' own description.
7575
class DocumentationIcon {
7676
/// Create an annotation to provide a URL to an image describing a class.
77-
const DocumentationIcon(this.url) : assert(url != null);
77+
const DocumentationIcon(this.url);
7878

7979
/// The URL to an image that represents the annotated class.
8080
final String url;
@@ -111,7 +111,7 @@ class DocumentationIcon {
111111
/// represents the class.
112112
class Summary {
113113
/// Create an annotation to provide a short description of a class.
114-
const Summary(this.text) : assert(text != null);
114+
const Summary(this.text);
115115

116116
/// The text of the summary of the annotated class.
117117
final String text;

packages/flutter/lib/src/foundation/assertions.dart

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ class PartialStackFrame {
5454
required this.package,
5555
required this.className,
5656
required this.method,
57-
}) : assert(className != null),
58-
assert(method != null),
59-
assert(package != null);
57+
});
6058

6159
/// An `<asynchronous suspension>` line in a stack trace.
6260
static const PartialStackFrame asynchronousSuspension = PartialStackFrame(
@@ -128,8 +126,7 @@ class RepetitiveStackFrameFilter extends StackFilter {
128126
const RepetitiveStackFrameFilter({
129127
required this.frames,
130128
required this.replacement,
131-
}) : assert(frames != null),
132-
assert(replacement != null);
129+
});
133130

134131
/// The shape of this repetitive stack pattern.
135132
final List<PartialStackFrame> frames;
@@ -177,8 +174,7 @@ abstract class _ErrorDiagnostic extends DiagnosticsProperty<List<Object>> {
177174
String message, {
178175
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.flat,
179176
DiagnosticLevel level = DiagnosticLevel.info,
180-
}) : assert(message != null),
181-
super(
177+
}) : super(
182178
null,
183179
<Object>[message],
184180
showName: false,
@@ -217,8 +213,7 @@ abstract class _ErrorDiagnostic extends DiagnosticsProperty<List<Object>> {
217213
List<Object> messageParts, {
218214
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.flat,
219215
DiagnosticLevel level = DiagnosticLevel.info,
220-
}) : assert(messageParts != null),
221-
super(
216+
}) : super(
222217
null,
223218
messageParts,
224219
showName: false,
@@ -406,7 +401,7 @@ class FlutterErrorDetails with Diagnosticable {
406401
this.stackFilter,
407402
this.informationCollector,
408403
this.silent = false,
409-
}) : assert(exception != null);
404+
});
410405

411406
/// Creates a copy of the error details but with the given fields replaced
412407
/// with new values.
@@ -1001,8 +996,6 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
1001996
///
1002997
/// The default behavior for the [onError] handler is to call this function.
1003998
static void dumpErrorToConsole(FlutterErrorDetails details, { bool forceReport = false }) {
1004-
assert(details != null);
1005-
assert(details.exception != null);
1006999
bool isInDebugMode = false;
10071000
assert(() {
10081001
// In debug mode, we ignore the "silent" flag.
@@ -1182,8 +1175,6 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
11821175
/// ```
11831176
/// {@end-tool}
11841177
static void reportError(FlutterErrorDetails details) {
1185-
assert(details != null);
1186-
assert(details.exception != null);
11871178
onError?.call(details);
11881179
}
11891180
}

packages/flutter/lib/src/foundation/basic_types.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class Factory<T> {
231231
/// Creates a new factory.
232232
///
233233
/// The `constructor` parameter must not be null.
234-
const Factory(this.constructor) : assert(constructor != null);
234+
const Factory(this.constructor);
235235

236236
/// Creates a new object of type T.
237237
final ValueGetter<T> constructor;

packages/flutter/lib/src/foundation/binding.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ abstract class BindingBase {
327327
]);
328328
}
329329
try {
330-
assert(instance != null);
331330
if (instance._debugConstructed && _debugInitializedType == null) {
332331
throw FlutterError.fromParts(<DiagnosticsNode>[
333332
ErrorSummary('Binding initialized without calling initInstances.'),
@@ -553,10 +552,8 @@ abstract class BindingBase {
553552
Future<void> lockEvents(Future<void> Function() callback) {
554553
final developer.TimelineTask timelineTask = developer.TimelineTask()..start('Lock events');
555554

556-
assert(callback != null);
557555
_lockCount += 1;
558556
final Future<void> future = callback();
559-
assert(future != null, 'The lockEvents() callback returned null; it should return a Future<void> that completes when the lock is to expire.');
560557
future.whenComplete(() {
561558
_lockCount -= 1;
562559
if (!locked) {
@@ -627,8 +624,6 @@ abstract class BindingBase {
627624
required String name,
628625
required AsyncCallback callback,
629626
}) {
630-
assert(name != null);
631-
assert(callback != null);
632627
registerServiceExtension(
633628
name: name,
634629
callback: (Map<String, String> parameters) async {
@@ -658,9 +653,6 @@ abstract class BindingBase {
658653
required AsyncValueGetter<bool> getter,
659654
required AsyncValueSetter<bool> setter,
660655
}) {
661-
assert(name != null);
662-
assert(getter != null);
663-
assert(setter != null);
664656
registerServiceExtension(
665657
name: name,
666658
callback: (Map<String, String> parameters) async {
@@ -692,9 +684,6 @@ abstract class BindingBase {
692684
required AsyncValueGetter<double> getter,
693685
required AsyncValueSetter<double> setter,
694686
}) {
695-
assert(name != null);
696-
assert(getter != null);
697-
assert(setter != null);
698687
registerServiceExtension(
699688
name: name,
700689
callback: (Map<String, String> parameters) async {
@@ -754,9 +743,6 @@ abstract class BindingBase {
754743
required AsyncValueGetter<String> getter,
755744
required AsyncValueSetter<String> setter,
756745
}) {
757-
assert(name != null);
758-
assert(getter != null);
759-
assert(setter != null);
760746
registerServiceExtension(
761747
name: name,
762748
callback: (Map<String, String> parameters) async {
@@ -825,8 +811,6 @@ abstract class BindingBase {
825811
required String name,
826812
required ServiceExtensionCallback callback,
827813
}) {
828-
assert(name != null);
829-
assert(callback != null);
830814
final String methodName = 'ext.flutter.$name';
831815
developer.registerExtension(methodName, (String method, Map<String, String> parameters) async {
832816
assert(method == methodName);

packages/flutter/lib/src/foundation/consolidate_response.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Future<Uint8List> consolidateHttpClientResponseBytes(
5151
bool autoUncompress = true,
5252
BytesReceivedCallback? onBytesReceived,
5353
}) {
54-
assert(autoUncompress != null);
5554
final Completer<Uint8List> completer = Completer<Uint8List>.sync();
5655

5756
final _OutputBuffer output = _OutputBuffer();

0 commit comments

Comments
 (0)