From 19dfde6989b14bd7dedbc50d7edceef4e59879a4 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Mon, 23 Jan 2023 11:29:48 -0800 Subject: [PATCH] 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 --- .../lib/src/foundation/annotations.dart | 6 +- .../lib/src/foundation/assertions.dart | 19 +-- .../lib/src/foundation/basic_types.dart | 2 +- .../flutter/lib/src/foundation/binding.dart | 16 --- .../src/foundation/consolidate_response.dart | 1 - .../lib/src/foundation/diagnostics.dart | 111 ++++-------------- packages/flutter/lib/src/foundation/node.dart | 3 - .../lib/src/foundation/serialization.dart | 3 +- .../lib/src/foundation/stack_frame.dart | 14 +-- .../lib/src/physics/clamped_simulation.dart | 3 +- .../lib/src/physics/gravity_simulation.dart | 6 +- .../lib/src/physics/spring_simulation.dart | 6 - packages/flutter/lib/src/physics/utils.dart | 1 - .../lib/src/services/asset_bundle.dart | 4 - .../flutter/lib/src/services/autofill.dart | 8 +- .../lib/src/services/message_codec.dart | 5 +- .../lib/src/services/message_codecs.dart | 1 - .../lib/src/services/mouse_cursor.dart | 9 +- .../lib/src/services/mouse_tracking.dart | 2 +- .../lib/src/services/platform_channel.dart | 15 +-- .../lib/src/services/platform_views.dart | 66 ++--------- .../src/services/raw_keyboard_android.dart | 7 +- .../src/services/raw_keyboard_fuchsia.dart | 5 +- .../lib/src/services/raw_keyboard_ios.dart | 5 +- .../lib/src/services/raw_keyboard_linux.dart | 7 +- .../lib/src/services/raw_keyboard_macos.dart | 5 +- .../lib/src/services/raw_keyboard_web.dart | 3 +- .../src/services/raw_keyboard_windows.dart | 5 +- .../flutter/lib/src/services/restoration.dart | 24 +--- .../flutter/lib/src/services/spell_check.dart | 10 +- .../lib/src/services/system_chrome.dart | 1 - .../lib/src/services/text_editing_delta.dart | 4 +- .../lib/src/services/text_formatter.dart | 7 +- .../flutter/lib/src/services/text_input.dart | 41 +------ 34 files changed, 77 insertions(+), 348 deletions(-) diff --git a/packages/flutter/lib/src/foundation/annotations.dart b/packages/flutter/lib/src/foundation/annotations.dart index b57bfac68e6..3bc5e023160 100644 --- a/packages/flutter/lib/src/foundation/annotations.dart +++ b/packages/flutter/lib/src/foundation/annotations.dart @@ -39,7 +39,7 @@ /// class that overrides the inline documentations' own description. class Category { /// Create an annotation to provide a categorization of a class. - const Category(this.sections) : assert(sections != null); + const Category(this.sections); /// The strings the correspond to the section and subsection of the /// category represented by this object. @@ -74,7 +74,7 @@ class Category { /// class that overrides the inline documentations' own description. class DocumentationIcon { /// Create an annotation to provide a URL to an image describing a class. - const DocumentationIcon(this.url) : assert(url != null); + const DocumentationIcon(this.url); /// The URL to an image that represents the annotated class. final String url; @@ -111,7 +111,7 @@ class DocumentationIcon { /// represents the class. class Summary { /// Create an annotation to provide a short description of a class. - const Summary(this.text) : assert(text != null); + const Summary(this.text); /// The text of the summary of the annotated class. final String text; diff --git a/packages/flutter/lib/src/foundation/assertions.dart b/packages/flutter/lib/src/foundation/assertions.dart index 253b0ae6b12..59abde71d27 100644 --- a/packages/flutter/lib/src/foundation/assertions.dart +++ b/packages/flutter/lib/src/foundation/assertions.dart @@ -54,9 +54,7 @@ class PartialStackFrame { required this.package, required this.className, required this.method, - }) : assert(className != null), - assert(method != null), - assert(package != null); + }); /// An `` line in a stack trace. static const PartialStackFrame asynchronousSuspension = PartialStackFrame( @@ -128,8 +126,7 @@ class RepetitiveStackFrameFilter extends StackFilter { const RepetitiveStackFrameFilter({ required this.frames, required this.replacement, - }) : assert(frames != null), - assert(replacement != null); + }); /// The shape of this repetitive stack pattern. final List frames; @@ -177,8 +174,7 @@ abstract class _ErrorDiagnostic extends DiagnosticsProperty> { String message, { DiagnosticsTreeStyle style = DiagnosticsTreeStyle.flat, DiagnosticLevel level = DiagnosticLevel.info, - }) : assert(message != null), - super( + }) : super( null, [message], showName: false, @@ -217,8 +213,7 @@ abstract class _ErrorDiagnostic extends DiagnosticsProperty> { List messageParts, { DiagnosticsTreeStyle style = DiagnosticsTreeStyle.flat, DiagnosticLevel level = DiagnosticLevel.info, - }) : assert(messageParts != null), - super( + }) : super( null, messageParts, showName: false, @@ -406,7 +401,7 @@ class FlutterErrorDetails with Diagnosticable { this.stackFilter, this.informationCollector, this.silent = false, - }) : assert(exception != null); + }); /// Creates a copy of the error details but with the given fields replaced /// with new values. @@ -1001,8 +996,6 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti /// /// The default behavior for the [onError] handler is to call this function. static void dumpErrorToConsole(FlutterErrorDetails details, { bool forceReport = false }) { - assert(details != null); - assert(details.exception != null); bool isInDebugMode = false; assert(() { // In debug mode, we ignore the "silent" flag. @@ -1182,8 +1175,6 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti /// ``` /// {@end-tool} static void reportError(FlutterErrorDetails details) { - assert(details != null); - assert(details.exception != null); onError?.call(details); } } diff --git a/packages/flutter/lib/src/foundation/basic_types.dart b/packages/flutter/lib/src/foundation/basic_types.dart index dc584115411..9bc8c6aa6e7 100644 --- a/packages/flutter/lib/src/foundation/basic_types.dart +++ b/packages/flutter/lib/src/foundation/basic_types.dart @@ -231,7 +231,7 @@ class Factory { /// Creates a new factory. /// /// The `constructor` parameter must not be null. - const Factory(this.constructor) : assert(constructor != null); + const Factory(this.constructor); /// Creates a new object of type T. final ValueGetter constructor; diff --git a/packages/flutter/lib/src/foundation/binding.dart b/packages/flutter/lib/src/foundation/binding.dart index 9bcf9284e98..c7fce102a79 100644 --- a/packages/flutter/lib/src/foundation/binding.dart +++ b/packages/flutter/lib/src/foundation/binding.dart @@ -327,7 +327,6 @@ abstract class BindingBase { ]); } try { - assert(instance != null); if (instance._debugConstructed && _debugInitializedType == null) { throw FlutterError.fromParts([ ErrorSummary('Binding initialized without calling initInstances.'), @@ -553,10 +552,8 @@ abstract class BindingBase { Future lockEvents(Future Function() callback) { final developer.TimelineTask timelineTask = developer.TimelineTask()..start('Lock events'); - assert(callback != null); _lockCount += 1; final Future future = callback(); - assert(future != null, 'The lockEvents() callback returned null; it should return a Future that completes when the lock is to expire.'); future.whenComplete(() { _lockCount -= 1; if (!locked) { @@ -627,8 +624,6 @@ abstract class BindingBase { required String name, required AsyncCallback callback, }) { - assert(name != null); - assert(callback != null); registerServiceExtension( name: name, callback: (Map parameters) async { @@ -658,9 +653,6 @@ abstract class BindingBase { required AsyncValueGetter getter, required AsyncValueSetter setter, }) { - assert(name != null); - assert(getter != null); - assert(setter != null); registerServiceExtension( name: name, callback: (Map parameters) async { @@ -692,9 +684,6 @@ abstract class BindingBase { required AsyncValueGetter getter, required AsyncValueSetter setter, }) { - assert(name != null); - assert(getter != null); - assert(setter != null); registerServiceExtension( name: name, callback: (Map parameters) async { @@ -754,9 +743,6 @@ abstract class BindingBase { required AsyncValueGetter getter, required AsyncValueSetter setter, }) { - assert(name != null); - assert(getter != null); - assert(setter != null); registerServiceExtension( name: name, callback: (Map parameters) async { @@ -825,8 +811,6 @@ abstract class BindingBase { required String name, required ServiceExtensionCallback callback, }) { - assert(name != null); - assert(callback != null); final String methodName = 'ext.flutter.$name'; developer.registerExtension(methodName, (String method, Map parameters) async { assert(method == methodName); diff --git a/packages/flutter/lib/src/foundation/consolidate_response.dart b/packages/flutter/lib/src/foundation/consolidate_response.dart index 4d0f44c039b..94160ec386b 100644 --- a/packages/flutter/lib/src/foundation/consolidate_response.dart +++ b/packages/flutter/lib/src/foundation/consolidate_response.dart @@ -51,7 +51,6 @@ Future consolidateHttpClientResponseBytes( bool autoUncompress = true, BytesReceivedCallback? onBytesReceived, }) { - assert(autoUncompress != null); final Completer completer = Completer.sync(); final _OutputBuffer output = _OutputBuffer(); diff --git a/packages/flutter/lib/src/foundation/diagnostics.dart b/packages/flutter/lib/src/foundation/diagnostics.dart index 80906dd7ca2..48e4161bc5a 100644 --- a/packages/flutter/lib/src/foundation/diagnostics.dart +++ b/packages/flutter/lib/src/foundation/diagnostics.dart @@ -253,28 +253,7 @@ class TextTreeConfiguration { this.beforeName = '', this.suffixLineOne = '', this.mandatoryFooter = '', - }) : assert(prefixLineOne != null), - assert(prefixOtherLines != null), - assert(prefixLastChildLineOne != null), - assert(prefixOtherLinesRootNode != null), - assert(linkCharacter != null), - assert(propertyPrefixIfChildren != null), - assert(propertyPrefixNoChildren != null), - assert(lineBreak != null), - assert(lineBreakProperties != null), - assert(afterName != null), - assert(afterDescriptionIfBody != null), - assert(afterDescription != null), - assert(beforeProperties != null), - assert(afterProperties != null), - assert(propertySeparator != null), - assert(bodyIndent != null), - assert(footer != null), - assert(showChildren != null), - assert(addBlankLineIfNoChildren != null), - assert(isNameOnOwnLine != null), - assert(isBlankLineBetweenPropertiesAndChildren != null), - childLinkSpace = ' ' * linkCharacter.length; + }) : childLinkSpace = ' ' * linkCharacter.length; /// Prefix to add to the first line to display a child with this style. final String prefixLineOne; @@ -1113,8 +1092,7 @@ class TextTreeRenderer { int wrapWidth = 100, int wrapWidthProperties = 65, int maxDescendentsTruncatableNode = -1, - }) : assert(minLevel != null), - _minLevel = minLevel, + }) : _minLevel = minLevel, _wrapWidth = wrapWidth, _wrapWidthProperties = wrapWidthProperties, _maxDescendentsTruncatableNode = maxDescendentsTruncatableNode; @@ -1218,7 +1196,7 @@ class TextTreeRenderer { List children = node.getChildren(); - String? description = node.toDescription(parentConfiguration: parentConfiguration); + String description = node.toDescription(parentConfiguration: parentConfiguration); if (config.beforeName.isNotEmpty) { builder.write(config.beforeName); } @@ -1229,7 +1207,7 @@ class TextTreeRenderer { if (uppercaseTitle) { name = name?.toUpperCase(); } - if (description == null || description.isEmpty) { + if (description.isEmpty) { if (node.showName && name != null) { builder.write(name, allowWrap: wrapName); } @@ -1388,7 +1366,6 @@ class TextTreeRenderer { for (int i = 0; i < children.length; i++) { final DiagnosticsNode child = children[i]; - assert(child != null); final TextTreeConfiguration childConfig = _childTextConfiguration(child, config)!; if (i == children.length - 1) { final String lastChildPrefixLineOne = '$prefixChildrenRaw${childConfig.prefixLastChildLineOne}'; @@ -1463,12 +1440,10 @@ abstract class DiagnosticsNode { this.showName = true, this.showSeparator = true, this.linePrefix, - }) : assert(showName != null), - assert(showSeparator != null), - // A name ending with ':' indicates that the user forgot that the ':' will - // be automatically added for them when generating descriptions of the - // property. - assert( + }) : assert( + // A name ending with ':' indicates that the user forgot that the ':' will + // be automatically added for them when generating descriptions of the + // property. name == null || !name.endsWith(':'), 'Names of diagnostic nodes must not end with colons.\n' 'name:\n' @@ -1490,8 +1465,6 @@ abstract class DiagnosticsNode { DiagnosticLevel level = DiagnosticLevel.info, bool allowWrap = true, }) { - assert(style != null); - assert(level != null); return DiagnosticsProperty( '', null, @@ -1728,7 +1701,6 @@ abstract class DiagnosticsNode { }) { String result = super.toString(); assert(style != null); - assert(minLevel != null); assert(() { if (_isSingleLine(style)) { result = toStringDeep(parentConfiguration: parentConfiguration, minLevel: minLevel); @@ -1866,11 +1838,7 @@ class MessageProperty extends DiagnosticsProperty { String message, { DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine, DiagnosticLevel level = DiagnosticLevel.info, - }) : assert(name != null), - assert(message != null), - assert(style != null), - assert(level != null), - super(name, null, description: message, style: style, level: level); + }) : super(name, null, description: message, style: style, level: level); } /// Property which encloses its string [value] in quotes. @@ -1894,10 +1862,7 @@ class StringProperty extends DiagnosticsProperty { super.ifEmpty, super.style, super.level, - }) : assert(showName != null), - assert(quoted != null), - assert(style != null), - assert(level != null); + }); /// Whether the value is enclosed in double quotes. final bool quoted; @@ -2005,9 +1970,7 @@ class DoubleProperty extends _NumProperty { super.showName, super.style, super.level, - }) : assert(showName != null), - assert(style != null), - assert(level != null); + }); /// Property with a [value] that is computed only when needed. /// @@ -2024,9 +1987,7 @@ class DoubleProperty extends _NumProperty { super.tooltip, super.defaultValue, super.level, - }) : assert(showName != null), - assert(level != null), - super.lazy(); + }) : super.lazy(); @override String numberToString() => debugFormatDouble(value); @@ -2048,9 +2009,7 @@ class IntProperty extends _NumProperty { super.defaultValue, super.style, super.level, - }) : assert(showName != null), - assert(level != null), - assert(style != null); + }); @override String numberToString() => value.toString(); @@ -2075,8 +2034,7 @@ class PercentProperty extends DoubleProperty { super.tooltip, super.unit, super.level, - }) : assert(showName != null), - assert(level != null); + }); @override String valueToString({ TextTreeConfiguration? parentConfiguration }) { @@ -2150,9 +2108,7 @@ class FlagProperty extends DiagnosticsProperty { bool showName = false, Object? defaultValue, DiagnosticLevel level = DiagnosticLevel.info, - }) : assert(showName != null), - assert(level != null), - assert(ifTrue != null || ifFalse != null), + }) : assert(ifTrue != null || ifFalse != null), super( name, value, @@ -2254,10 +2210,7 @@ class IterableProperty extends DiagnosticsProperty> { super.showName, super.showSeparator, super.level, - }) : assert(style != null), - assert(showName != null), - assert(showSeparator != null), - assert(level != null); + }); @override String valueToString({TextTreeConfiguration? parentConfiguration}) { @@ -2335,7 +2288,7 @@ class EnumProperty extends DiagnosticsProperty { super.value, { super.defaultValue, super.level, - }) : assert(level != null); + }); @override String valueToString({ TextTreeConfiguration? parentConfiguration }) { @@ -2382,9 +2335,7 @@ class ObjectFlagProperty extends DiagnosticsProperty { super.ifNull, super.showName = false, super.level, - }) : assert(ifPresent != null || ifNull != null), - assert(showName != null), - assert(level != null); + }) : assert(ifPresent != null || ifNull != null); /// Shorthand constructor to describe whether the property has a value. /// @@ -2396,9 +2347,7 @@ class ObjectFlagProperty extends DiagnosticsProperty { String super.name, super.value, { super.level, - }) : assert(name != null), - assert(level != null), - ifPresent = 'has $name', + }) : ifPresent = 'has $name', super( showName: false, ); @@ -2495,17 +2444,13 @@ class FlagsSummary extends DiagnosticsProperty> { super.showName, super.showSeparator, super.level, - }) : assert(value != null), - assert(showName != null), - assert(showSeparator != null), - assert(level != null); + }); @override Map get value => super.value!; @override String valueToString({TextTreeConfiguration? parentConfiguration}) { - assert(value != null); if (!_hasNonNullEntry() && ifEmpty != null) { return ifEmpty!; } @@ -2598,11 +2543,7 @@ class DiagnosticsProperty extends DiagnosticsNode { this.allowNameWrap = true, DiagnosticsTreeStyle super.style = DiagnosticsTreeStyle.singleLine, DiagnosticLevel level = DiagnosticLevel.info, - }) : assert(showName != null), - assert(showSeparator != null), - assert(style != null), - assert(level != null), - _description = description, + }) : _description = description, _valueComputed = true, _value = value, _computeValue = null, @@ -2640,12 +2581,7 @@ class DiagnosticsProperty extends DiagnosticsNode { this.allowNameWrap = true, DiagnosticsTreeStyle super.style = DiagnosticsTreeStyle.singleLine, DiagnosticLevel level = DiagnosticLevel.info, - }) : assert(showName != null), - assert(showSeparator != null), - assert(defaultValue == kNoDefaultValue || defaultValue is T?), - assert(missingIfNull != null), - assert(style != null), - assert(level != null), + }) : assert(defaultValue == kNoDefaultValue || defaultValue is T?), _description = description, _valueComputed = false, _value = null, @@ -2765,7 +2701,6 @@ class DiagnosticsProperty extends DiagnosticsNode { /// /// `text` must not be null. String _addTooltip(String text) { - assert(text != null); return tooltip == null ? text : '$text ($tooltip)'; } @@ -2938,7 +2873,7 @@ class DiagnosticableNode extends DiagnosticsNode { super.name, required this.value, required super.style, - }) : assert(value != null); + }); @override final T value; diff --git a/packages/flutter/lib/src/foundation/node.dart b/packages/flutter/lib/src/foundation/node.dart index f8c377ba9e3..6e830f180a3 100644 --- a/packages/flutter/lib/src/foundation/node.dart +++ b/packages/flutter/lib/src/foundation/node.dart @@ -92,7 +92,6 @@ class AbstractNode { /// method, as in `super.attach(owner)`. @mustCallSuper void attach(covariant Object owner) { - assert(owner != null); assert(_owner == null); _owner = owner; } @@ -124,7 +123,6 @@ class AbstractNode { @protected @mustCallSuper void adoptChild(covariant AbstractNode child) { - assert(child != null); assert(child._parent == null); assert(() { AbstractNode node = this; @@ -147,7 +145,6 @@ class AbstractNode { @protected @mustCallSuper void dropChild(covariant AbstractNode child) { - assert(child != null); assert(child._parent == this); assert(child.attached == attached); child._parent = null; diff --git a/packages/flutter/lib/src/foundation/serialization.dart b/packages/flutter/lib/src/foundation/serialization.dart index b0ade7d1584..bdeaecc51ad 100644 --- a/packages/flutter/lib/src/foundation/serialization.dart +++ b/packages/flutter/lib/src/foundation/serialization.dart @@ -170,8 +170,7 @@ class WriteBuffer { /// The byte order used is [Endian.host] throughout. class ReadBuffer { /// Creates a [ReadBuffer] for reading from the specified [data]. - ReadBuffer(this.data) - : assert(data != null); + ReadBuffer(this.data); /// The underlying data being read. final ByteData data; diff --git a/packages/flutter/lib/src/foundation/stack_frame.dart b/packages/flutter/lib/src/foundation/stack_frame.dart index 1a18d2d17d9..5e22e1e82ac 100644 --- a/packages/flutter/lib/src/foundation/stack_frame.dart +++ b/packages/flutter/lib/src/foundation/stack_frame.dart @@ -35,16 +35,7 @@ class StackFrame { required this.method, this.isConstructor = false, required this.source, - }) : assert(number != null), - assert(column != null), - assert(line != null), - assert(method != null), - assert(packageScheme != null), - assert(package != null), - assert(packagePath != null), - assert(className != null), - assert(isConstructor != null), - assert(source != null); + }); /// A stack frame representing an asynchronous suspension. static const StackFrame asynchronousSuspension = StackFrame( @@ -74,13 +65,11 @@ class StackFrame { /// /// This is normally useful with [StackTrace.current]. static List fromStackTrace(StackTrace stack) { - assert(stack != null); return fromStackString(stack.toString()); } /// Parses a list of [StackFrame]s from the [StackTrace.toString] method. static List fromStackString(String stack) { - assert(stack != null); return stack .trim() .split('\n') @@ -181,7 +170,6 @@ class StackFrame { /// Parses a single [StackFrame] from a single line of a [StackTrace]. static StackFrame? fromStackTraceLine(String line) { - assert(line != null); if (line == '') { return asynchronousSuspension; } else if (line == '...') { diff --git a/packages/flutter/lib/src/physics/clamped_simulation.dart b/packages/flutter/lib/src/physics/clamped_simulation.dart index 943ea80358a..dfd889d284a 100644 --- a/packages/flutter/lib/src/physics/clamped_simulation.dart +++ b/packages/flutter/lib/src/physics/clamped_simulation.dart @@ -36,8 +36,7 @@ class ClampedSimulation extends Simulation { this.xMax = double.infinity, this.dxMin = double.negativeInfinity, this.dxMax = double.infinity, - }) : assert(simulation != null), - assert(xMax >= xMin), + }) : assert(xMax >= xMin), assert(dxMax >= dxMin); /// The simulation being clamped. Calls to [x], [dx], and [isDone] are diff --git a/packages/flutter/lib/src/physics/gravity_simulation.dart b/packages/flutter/lib/src/physics/gravity_simulation.dart index d3715e2f9db..56f02ed933a 100644 --- a/packages/flutter/lib/src/physics/gravity_simulation.dart +++ b/packages/flutter/lib/src/physics/gravity_simulation.dart @@ -70,11 +70,7 @@ class GravitySimulation extends Simulation { double distance, double endDistance, double velocity, - ) : assert(acceleration != null), - assert(distance != null), - assert(velocity != null), - assert(endDistance != null), - assert(endDistance >= 0), + ) : assert(endDistance >= 0), _a = acceleration, _x = distance, _v = velocity, diff --git a/packages/flutter/lib/src/physics/spring_simulation.dart b/packages/flutter/lib/src/physics/spring_simulation.dart index 90803109ff2..b4b615a29cf 100644 --- a/packages/flutter/lib/src/physics/spring_simulation.dart +++ b/packages/flutter/lib/src/physics/spring_simulation.dart @@ -153,12 +153,6 @@ abstract class _SpringSolution { double initialPosition, double initialVelocity, ) { - assert(spring != null); - assert(spring.mass != null); - assert(spring.stiffness != null); - assert(spring.damping != null); - assert(initialPosition != null); - assert(initialVelocity != null); final double cmk = spring.damping * spring.damping - 4 * spring.mass * spring.stiffness; if (cmk == 0.0) { return _CriticalSolution(spring, initialPosition, initialVelocity); diff --git a/packages/flutter/lib/src/physics/utils.dart b/packages/flutter/lib/src/physics/utils.dart index 7b9501b7a62..7a8f82ecdff 100644 --- a/packages/flutter/lib/src/physics/utils.dart +++ b/packages/flutter/lib/src/physics/utils.dart @@ -8,7 +8,6 @@ /// The `a` and `b` arguments may be null. A null value is only considered /// near-equal to another null value. bool nearEqual(double? a, double? b, double epsilon) { - assert(epsilon != null); assert(epsilon >= 0.0); if (a == null || b == null) { return a == b; diff --git a/packages/flutter/lib/src/services/asset_bundle.dart b/packages/flutter/lib/src/services/asset_bundle.dart index 776035aa687..971fdaf58fb 100644 --- a/packages/flutter/lib/src/services/asset_bundle.dart +++ b/packages/flutter/lib/src/services/asset_bundle.dart @@ -151,8 +151,6 @@ class NetworkAssetBundle extends AssetBundle { /// fetched. @override Future loadStructuredData(String key, Future Function(String value) parser) async { - assert(key != null); - assert(parser != null); return parser(await loadString(key)); } @@ -196,8 +194,6 @@ abstract class CachingAssetBundle extends AssetBundle { /// callback synchronously. @override Future loadStructuredData(String key, Future Function(String value) parser) { - assert(key != null); - assert(parser != null); if (_structuredDataCache.containsKey(key)) { return _structuredDataCache[key]! as Future; } diff --git a/packages/flutter/lib/src/services/autofill.dart b/packages/flutter/lib/src/services/autofill.dart index f1dd457d14b..8cf825fc5f7 100644 --- a/packages/flutter/lib/src/services/autofill.dart +++ b/packages/flutter/lib/src/services/autofill.dart @@ -651,8 +651,7 @@ class AutofillConfiguration { this.autofillHints = const [], this.hintText, required this.currentEditingValue, - }) : assert(uniqueIdentifier != null), - assert(autofillHints != null); + }); /// An [AutofillConfiguration] that indicates the [AutofillClient] does not /// wish to be autofilled. @@ -810,9 +809,7 @@ class _AutofillScopeTextInputConfiguration extends TextInputConfiguration { _AutofillScopeTextInputConfiguration({ required this.allConfigurations, required TextInputConfiguration currentClientConfiguration, - }) : assert(allConfigurations != null), - assert(currentClientConfiguration != null), - super(inputType: currentClientConfiguration.inputType, + }) : super(inputType: currentClientConfiguration.inputType, obscureText: currentClientConfiguration.obscureText, autocorrect: currentClientConfiguration.autocorrect, smartDashesType: currentClientConfiguration.smartDashesType, @@ -843,7 +840,6 @@ class _AutofillScopeTextInputConfiguration extends TextInputConfiguration { mixin AutofillScopeMixin implements AutofillScope { @override TextInputConnection attach(TextInputClient trigger, TextInputConfiguration configuration) { - assert(trigger != null); assert( !autofillClients.any((AutofillClient client) => !client.textInputConfiguration.autofillConfiguration.enabled), 'Every client in AutofillScope.autofillClients must enable autofill', diff --git a/packages/flutter/lib/src/services/message_codec.dart b/packages/flutter/lib/src/services/message_codec.dart index fd45d29ce2a..cc2efd41a3d 100644 --- a/packages/flutter/lib/src/services/message_codec.dart +++ b/packages/flutter/lib/src/services/message_codec.dart @@ -34,8 +34,7 @@ abstract class MessageCodec { class MethodCall { /// Creates a [MethodCall] representing the invocation of [method] with the /// specified [arguments]. - const MethodCall(this.method, [this.arguments]) - : assert(method != null); + const MethodCall(this.method, [this.arguments]); /// The name of the method to be called. final String method; @@ -114,7 +113,7 @@ class PlatformException implements Exception { this.message, this.details, this.stacktrace, - }) : assert(code != null); + }); /// An error code. final String code; diff --git a/packages/flutter/lib/src/services/message_codecs.dart b/packages/flutter/lib/src/services/message_codecs.dart index 6aecc8607d6..fcd90731caf 100644 --- a/packages/flutter/lib/src/services/message_codecs.dart +++ b/packages/flutter/lib/src/services/message_codecs.dart @@ -195,7 +195,6 @@ class JSONMethodCodec implements MethodCodec { @override ByteData encodeErrorEnvelope({ required String code, String? message, Object? details}) { - assert(code != null); return const JSONMessageCodec().encodeMessage([code, message, details])!; } } diff --git a/packages/flutter/lib/src/services/mouse_cursor.dart b/packages/flutter/lib/src/services/mouse_cursor.dart index 5abe5cc08c9..c698aa0b0bc 100644 --- a/packages/flutter/lib/src/services/mouse_cursor.dart +++ b/packages/flutter/lib/src/services/mouse_cursor.dart @@ -104,9 +104,7 @@ abstract class MouseCursorSession { /// Create a session. /// /// All arguments must be non-null. - MouseCursorSession(this.cursor, this.device) - : assert(cursor != null), - assert(device != null); + MouseCursorSession(this.cursor, this.device); /// The cursor that created this session. final MouseCursor cursor; @@ -215,7 +213,7 @@ abstract class MouseCursor with Diagnosticable { @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { final String debugDescription = this.debugDescription; - if (minLevel.index >= DiagnosticLevel.info.index && debugDescription != null) { + if (minLevel.index >= DiagnosticLevel.info.index) { return debugDescription; } return super.toString(minLevel: minLevel); @@ -262,7 +260,6 @@ class _DeferringMouseCursor extends MouseCursor { /// Returns the first cursor that is not a [MouseCursor.defer]. static MouseCursor? firstNonDeferred(Iterable cursors) { for (final MouseCursor cursor in cursors) { - assert(cursor != null); if (cursor != MouseCursor.defer) { return cursor; } @@ -358,7 +355,7 @@ class SystemMouseCursor extends MouseCursor { // the supported system cursors are enumerated in [SystemMouseCursors]. const SystemMouseCursor._({ required this.kind, - }) : assert(kind != null); + }); /// A string that identifies the kind of the cursor. /// diff --git a/packages/flutter/lib/src/services/mouse_tracking.dart b/packages/flutter/lib/src/services/mouse_tracking.dart index a66216db2fd..e0c405b90db 100644 --- a/packages/flutter/lib/src/services/mouse_tracking.dart +++ b/packages/flutter/lib/src/services/mouse_tracking.dart @@ -51,7 +51,7 @@ class MouseTrackerAnnotation with Diagnosticable { this.onExit, this.cursor = MouseCursor.defer, this.validForMouseTracker = true, - }) : assert(cursor != null); + }); /// Triggered when a mouse pointer, with or without buttons pressed, has /// entered the region and [validForMouseTracker] is true. diff --git a/packages/flutter/lib/src/services/platform_channel.dart b/packages/flutter/lib/src/services/platform_channel.dart index d718de950c5..6106302529d 100644 --- a/packages/flutter/lib/src/services/platform_channel.dart +++ b/packages/flutter/lib/src/services/platform_channel.dart @@ -163,9 +163,7 @@ class BasicMessageChannel { /// The [name] and [codec] arguments cannot be null. The default [ServicesBinding.defaultBinaryMessenger] /// instance is used if [binaryMessenger] is null. const BasicMessageChannel(this.name, this.codec, { BinaryMessenger? binaryMessenger }) - : assert(name != null), - assert(codec != null), - _binaryMessenger = binaryMessenger; + : _binaryMessenger = binaryMessenger; /// The logical channel on which communication happens, not null. final String name; @@ -253,9 +251,7 @@ class MethodChannel { /// The [name] and [codec] arguments cannot be null. The default [ServicesBinding.defaultBinaryMessenger] /// instance is used if [binaryMessenger] is null. const MethodChannel(this.name, [this.codec = const StandardMethodCodec(), BinaryMessenger? binaryMessenger ]) - : assert(name != null), - assert(codec != null), - _binaryMessenger = binaryMessenger; + : _binaryMessenger = binaryMessenger; /// The logical channel on which communication happens, not null. final String name; @@ -300,7 +296,6 @@ class MethodChannel { /// nullable. @optionalTypeArgs Future _invokeMethod(String method, { required bool missingOk, dynamic arguments }) async { - assert(method != null); final ByteData input = codec.encodeMethodCall(MethodCall(method, arguments)); final ByteData? result = !kReleaseMode && debugProfilePlatformChannels ? @@ -535,7 +530,7 @@ class MethodChannel { /// Any other exception results in an error envelope being sent. void setMethodCallHandler(Future Function(MethodCall call)? handler) { assert( - _binaryMessenger != null || ServicesBinding.instance != null, + _binaryMessenger != null || BindingBase.debugBindingType() != null, 'Cannot set the method call handler before the binary messenger has been initialized. ' 'This happens when you call setMethodCallHandler() before the WidgetsFlutterBinding ' 'has been initialized. You can fix this by either calling WidgetsFlutterBinding.ensureInitialized() ' @@ -609,9 +604,7 @@ class EventChannel { /// Neither [name] nor [codec] may be null. The default [ServicesBinding.defaultBinaryMessenger] /// instance is used if [binaryMessenger] is null. const EventChannel(this.name, [this.codec = const StandardMethodCodec(), BinaryMessenger? binaryMessenger]) - : assert(name != null), - assert(codec != null), - _binaryMessenger = binaryMessenger; + : _binaryMessenger = binaryMessenger; /// The logical channel on which communication happens, not null. final String name; diff --git a/packages/flutter/lib/src/services/platform_views.dart b/packages/flutter/lib/src/services/platform_views.dart index 001acb76ae4..fb903dd4a60 100644 --- a/packages/flutter/lib/src/services/platform_views.dart +++ b/packages/flutter/lib/src/services/platform_views.dart @@ -119,9 +119,6 @@ class PlatformViewsService { MessageCodec? creationParamsCodec, VoidCallback? onFocus, }) { - assert(id != null); - assert(viewType != null); - assert(layoutDirection != null); assert(creationParams == null || creationParamsCodec != null); final TextureAndroidViewController controller = TextureAndroidViewController._( @@ -150,9 +147,6 @@ class PlatformViewsService { MessageCodec? creationParamsCodec, VoidCallback? onFocus, }) { - assert(id != null); - assert(viewType != null); - assert(layoutDirection != null); assert(creationParams == null || creationParamsCodec != null); final SurfaceAndroidViewController controller = SurfaceAndroidViewController._( @@ -222,9 +216,6 @@ class PlatformViewsService { MessageCodec? creationParamsCodec, VoidCallback? onFocus, }) async { - assert(id != null); - assert(viewType != null); - assert(layoutDirection != null); assert(creationParams == null || creationParamsCodec != null); // TODO(amirh): pass layoutDirection once the system channel supports it. @@ -258,8 +249,7 @@ class AndroidPointerProperties { const AndroidPointerProperties({ required this.id, required this.toolType, - }) : assert(id != null), - assert(toolType != null); + }); /// See Android's [MotionEvent.PointerProperties#id](https://developer.android.com/reference/android/view/MotionEvent.PointerProperties.html#id). final int id; @@ -308,15 +298,7 @@ class AndroidPointerCoords { required this.touchMinor, required this.x, required this.y, - }) : assert(orientation != null), - assert(pressure != null), - assert(size != null), - assert(toolMajor != null), - assert(toolMinor != null), - assert(touchMajor != null), - assert(touchMinor != null), - assert(x != null), - assert(y != null); + }); /// The orientation of the touch area and tool area in radians clockwise from vertical. /// @@ -404,21 +386,7 @@ class AndroidMotionEvent { required this.source, required this.flags, required this.motionEventId, - }) : assert(downTime != null), - assert(eventTime != null), - assert(action != null), - assert(pointerCount != null), - assert(pointerProperties != null), - assert(pointerCoords != null), - assert(metaState != null), - assert(buttonState != null), - assert(xPrecision != null), - assert(yPrecision != null), - assert(deviceId != null), - assert(edgeFlags != null), - assert(source != null), - assert(flags != null), - assert(pointerProperties.length == pointerCount), + }) : assert(pointerProperties.length == pointerCount), assert(pointerCoords.length == pointerCount); /// The time (in ms) when the user originally pressed down to start a stream of position events, @@ -532,12 +500,7 @@ class _AndroidMotionEventConverter { {}; final Set usedAndroidPointerIds = {}; - PointTransformer get pointTransformer => _pointTransformer; - late PointTransformer _pointTransformer; - set pointTransformer(PointTransformer transformer) { - assert(transformer != null); - _pointTransformer = transformer; - } + late PointTransformer pointTransformer; int? downTimeMillis; @@ -554,7 +517,7 @@ class _AndroidMotionEventConverter { } void updatePointerPositions(PointerEvent event) { - final Offset position = _pointTransformer(event.position); + final Offset position = pointTransformer(event.position); pointerPositions[event.pointer] = AndroidPointerCoords( orientation: event.orientation, pressure: event.pressure, @@ -691,10 +654,7 @@ abstract class AndroidViewController extends PlatformViewController { required TextDirection layoutDirection, dynamic creationParams, MessageCodec? creationParamsCodec, - }) : assert(viewId != null), - assert(viewType != null), - assert(layoutDirection != null), - assert(creationParams == null || creationParamsCodec != null), + }) : assert(creationParams == null || creationParamsCodec != null), _viewType = viewType, _layoutDirection = layoutDirection, _creationParams = creationParams == null ? null : _CreationParams(creationParams, creationParamsCodec!); @@ -755,7 +715,6 @@ abstract class AndroidViewController extends PlatformViewController { []; static int _getAndroidDirection(TextDirection direction) { - assert(direction != null); switch (direction) { case TextDirection.ltr: return kAndroidLayoutDirectionLtr; @@ -874,10 +833,9 @@ abstract class AndroidViewController extends PlatformViewController { /// /// This is required to convert a [PointerEvent] to an [AndroidMotionEvent]. /// It is typically provided by using [RenderBox.globalToLocal]. - PointTransformer get pointTransformer => _motionEventConverter._pointTransformer; + PointTransformer get pointTransformer => _motionEventConverter.pointTransformer; set pointTransformer(PointTransformer transformer) { - assert(transformer != null); - _motionEventConverter._pointTransformer = transformer; + _motionEventConverter.pointTransformer = transformer; } /// Whether the platform view has already been created. @@ -886,14 +844,12 @@ abstract class AndroidViewController extends PlatformViewController { /// Adds a callback that will get invoke after the platform view has been /// created. void addOnPlatformViewCreatedListener(PlatformViewCreatedCallback listener) { - assert(listener != null); assert(_state != _AndroidViewState.disposed); _platformViewCreatedCallbacks.add(listener); } /// Removes a callback added with [addOnPlatformViewCreatedListener]. void removeOnPlatformViewCreatedListener(PlatformViewCreatedCallback listener) { - assert(listener != null); assert(_state != _AndroidViewState.disposed); _platformViewCreatedCallbacks.remove(listener); } @@ -914,7 +870,6 @@ abstract class AndroidViewController extends PlatformViewController { return; } - assert(layoutDirection != null); _layoutDirection = layoutDirection; // If the view was not yet created we just update _layoutDirection and return, as the new @@ -1361,9 +1316,7 @@ class UiKitViewController { UiKitViewController._( this.id, TextDirection layoutDirection, - ) : assert(id != null), - assert(layoutDirection != null), - _layoutDirection = layoutDirection; + ) : _layoutDirection = layoutDirection; /// The unique identifier of the iOS view controlled by this controller. @@ -1384,7 +1337,6 @@ class UiKitViewController { return; } - assert(layoutDirection != null); _layoutDirection = layoutDirection; // TODO(amirh): invoke the iOS platform views channel direction method once available. diff --git a/packages/flutter/lib/src/services/raw_keyboard_android.dart b/packages/flutter/lib/src/services/raw_keyboard_android.dart index 7c39a3e1c2d..4de79dad956 100644 --- a/packages/flutter/lib/src/services/raw_keyboard_android.dart +++ b/packages/flutter/lib/src/services/raw_keyboard_android.dart @@ -42,11 +42,7 @@ class RawKeyEventDataAndroid extends RawKeyEventData { this.productId = 0, this.deviceId = 0, this.repeatCount = 0, - }) : assert(flags != null), - assert(codePoint != null), - assert(keyCode != null), - assert(scanCode != null), - assert(metaState != null); + }); /// The current set of additional flags for this event. /// @@ -227,7 +223,6 @@ class RawKeyEventDataAndroid extends RawKeyEventData { @override bool isModifierPressed(ModifierKey key, { KeyboardSide side = KeyboardSide.any }) { - assert(side != null); switch (key) { case ModifierKey.controlModifier: return _isLeftRightModifierPressed(side, modifierControl, modifierLeftControl, modifierRightControl); diff --git a/packages/flutter/lib/src/services/raw_keyboard_fuchsia.dart b/packages/flutter/lib/src/services/raw_keyboard_fuchsia.dart index 5158117f14a..3f74d084005 100644 --- a/packages/flutter/lib/src/services/raw_keyboard_fuchsia.dart +++ b/packages/flutter/lib/src/services/raw_keyboard_fuchsia.dart @@ -28,9 +28,7 @@ class RawKeyEventDataFuchsia extends RawKeyEventData { this.hidUsage = 0, this.codePoint = 0, this.modifiers = 0, - }) : assert(hidUsage != null), - assert(codePoint != null), - assert(modifiers != null); + }); /// The USB HID usage. /// @@ -107,7 +105,6 @@ class RawKeyEventDataFuchsia extends RawKeyEventData { @override bool isModifierPressed(ModifierKey key, { KeyboardSide side = KeyboardSide.any }) { - assert(side != null); switch (key) { case ModifierKey.controlModifier: return _isLeftRightModifierPressed(side, modifierControl, modifierLeftControl, modifierRightControl); diff --git a/packages/flutter/lib/src/services/raw_keyboard_ios.dart b/packages/flutter/lib/src/services/raw_keyboard_ios.dart index 4ee5f5d226f..00ecd43e6b7 100644 --- a/packages/flutter/lib/src/services/raw_keyboard_ios.dart +++ b/packages/flutter/lib/src/services/raw_keyboard_ios.dart @@ -30,10 +30,7 @@ class RawKeyEventDataIos extends RawKeyEventData { this.charactersIgnoringModifiers = '', this.keyCode = 0, this.modifiers = 0, - }) : assert(characters != null), - assert(charactersIgnoringModifiers != null), - assert(keyCode != null), - assert(modifiers != null); + }); /// The Unicode characters associated with a key-up or key-down event. /// diff --git a/packages/flutter/lib/src/services/raw_keyboard_linux.dart b/packages/flutter/lib/src/services/raw_keyboard_linux.dart index c7e0d21a779..70d139d57a4 100644 --- a/packages/flutter/lib/src/services/raw_keyboard_linux.dart +++ b/packages/flutter/lib/src/services/raw_keyboard_linux.dart @@ -33,12 +33,7 @@ class RawKeyEventDataLinux extends RawKeyEventData { this.modifiers = 0, required this.isDown, this.specifiedLogicalKey, - }) : assert(scanCode != null), - assert(unicodeScalarValues != null), - assert((unicodeScalarValues & ~LogicalKeyboardKey.valueMask) == 0), - assert(keyCode != null), - assert(modifiers != null), - assert(keyHelper != null); + }) : assert((unicodeScalarValues & ~LogicalKeyboardKey.valueMask) == 0); /// A helper class that abstracts the fetching of the toolkit-specific mappings. /// diff --git a/packages/flutter/lib/src/services/raw_keyboard_macos.dart b/packages/flutter/lib/src/services/raw_keyboard_macos.dart index 952ec0cabd7..c4e140b952f 100644 --- a/packages/flutter/lib/src/services/raw_keyboard_macos.dart +++ b/packages/flutter/lib/src/services/raw_keyboard_macos.dart @@ -42,10 +42,7 @@ class RawKeyEventDataMacOs extends RawKeyEventData { this.keyCode = 0, this.modifiers = 0, this.specifiedLogicalKey, - }) : assert(characters != null), - assert(charactersIgnoringModifiers != null), - assert(keyCode != null), - assert(modifiers != null); + }); /// The Unicode characters associated with a key-up or key-down event. /// diff --git a/packages/flutter/lib/src/services/raw_keyboard_web.dart b/packages/flutter/lib/src/services/raw_keyboard_web.dart index 3ad7a6fb3fd..8cc289b79d2 100644 --- a/packages/flutter/lib/src/services/raw_keyboard_web.dart +++ b/packages/flutter/lib/src/services/raw_keyboard_web.dart @@ -35,8 +35,7 @@ class RawKeyEventDataWeb extends RawKeyEventData { this.location = 0, this.metaState = modifierNone, this.keyCode = 0, - }) : assert(code != null), - assert(metaState != null); + }); /// The `KeyboardEvent.code` corresponding to this event. /// diff --git a/packages/flutter/lib/src/services/raw_keyboard_windows.dart b/packages/flutter/lib/src/services/raw_keyboard_windows.dart index d9f97978c1e..a8b01d07c4e 100644 --- a/packages/flutter/lib/src/services/raw_keyboard_windows.dart +++ b/packages/flutter/lib/src/services/raw_keyboard_windows.dart @@ -35,10 +35,7 @@ class RawKeyEventDataWindows extends RawKeyEventData { this.scanCode = 0, this.characterCodePoint = 0, this.modifiers = 0, - }) : assert(keyCode != null), - assert(scanCode != null), - assert(characterCodePoint != null), - assert(modifiers != null); + }); /// The hardware key code corresponding to this key event. /// diff --git a/packages/flutter/lib/src/services/restoration.dart b/packages/flutter/lib/src/services/restoration.dart index e2f59d5e403..1ff50e6a401 100644 --- a/packages/flutter/lib/src/services/restoration.dart +++ b/packages/flutter/lib/src/services/restoration.dart @@ -259,7 +259,6 @@ class RestorationManager extends ChangeNotifier { /// called. @protected void handleRestorationUpdateFromEngine({required bool enabled, required Uint8List? data}) { - assert(enabled != null); assert(enabled || data == null); _isReplacing = _rootBucketIsValid && enabled; @@ -297,7 +296,6 @@ class RestorationManager extends ChangeNotifier { /// by the data. @protected Future sendToEngine(Uint8List encodedData) { - assert(encodedData != null); return SystemChannels.restoration.invokeMethod( 'put', encodedData, @@ -344,7 +342,6 @@ class RestorationManager extends ChangeNotifier { @protected @visibleForTesting void scheduleSerializationFor(RestorationBucket bucket) { - assert(bucket != null); assert(bucket._manager == this); assert(!_debugDoingUpdate); _bucketsNeedingSerialization.add(bucket); @@ -366,7 +363,6 @@ class RestorationManager extends ChangeNotifier { @protected @visibleForTesting void unscheduleSerializationFor(RestorationBucket bucket) { - assert(bucket != null); assert(bucket._manager == this); assert(!_debugDoingUpdate); _bucketsNeedingSerialization.remove(bucket); @@ -502,8 +498,7 @@ class RestorationBucket { RestorationBucket.empty({ required String restorationId, required Object? debugOwner, - }) : assert(restorationId != null), - _restorationId = restorationId, + }) : _restorationId = restorationId, _rawData = {} { assert(() { _debugOwner = debugOwner; @@ -537,8 +532,7 @@ class RestorationBucket { RestorationBucket.root({ required RestorationManager manager, required Map? rawData, - }) : assert(manager != null), - _manager = manager, + }) : _manager = manager, _rawData = rawData ?? {}, _restorationId = 'root' { assert(() { @@ -561,9 +555,7 @@ class RestorationBucket { required String restorationId, required RestorationBucket parent, required Object? debugOwner, - }) : assert(restorationId != null), - assert(parent != null), - assert(parent._rawChildren[restorationId] != null), + }) : assert(parent._rawChildren[restorationId] != null), _manager = parent._manager, _parent = parent, _rawData = parent._rawChildren[restorationId]! as Map, @@ -635,7 +627,6 @@ class RestorationBucket { /// restoration ID. P? read

(String restorationId) { assert(_debugAssertNotDisposed()); - assert(restorationId != null); return _rawValues[restorationId] as P?; } @@ -657,7 +648,6 @@ class RestorationBucket { /// restoration ID. void write

(String restorationId, P value) { assert(_debugAssertNotDisposed()); - assert(restorationId != null); assert(debugIsSerializableForRestoration(value)); if (_rawValues[restorationId] != value || !_rawValues.containsKey(restorationId)) { _rawValues[restorationId] = value; @@ -679,7 +669,6 @@ class RestorationBucket { /// restoration ID. P? remove

(String restorationId) { assert(_debugAssertNotDisposed()); - assert(restorationId != null); final bool needsUpdate = _rawValues.containsKey(restorationId); final P? result = _rawValues.remove(restorationId) as P?; if (_rawValues.isEmpty) { @@ -701,7 +690,6 @@ class RestorationBucket { /// * [remove], which removes a value from the bucket. bool contains(String restorationId) { assert(_debugAssertNotDisposed()); - assert(restorationId != null); return _rawValues.containsKey(restorationId); } @@ -737,7 +725,6 @@ class RestorationBucket { /// delete the information stored in it from the app's restoration data. RestorationBucket claimChild(String restorationId, {required Object? debugOwner}) { assert(_debugAssertNotDisposed()); - assert(restorationId != null); // There are three cases to consider: // 1. Claiming an ID that has already been claimed. // 2. Claiming an ID that doesn't yet exist in [_rawChildren]. @@ -787,7 +774,6 @@ class RestorationBucket { /// No-op if the provided bucket is already a child of this bucket. void adoptChild(RestorationBucket child) { assert(_debugAssertNotDisposed()); - assert(child != null); if (child._parent != this) { child._parent?._removeChildData(child); child._parent = this; @@ -801,7 +787,6 @@ class RestorationBucket { } void _dropChild(RestorationBucket child) { - assert(child != null); assert(child._parent == this); _removeChildData(child); child._parent = null; @@ -876,7 +861,6 @@ class RestorationBucket { } void _removeChildData(RestorationBucket child) { - assert(child != null); assert(child._parent == this); if (_claimedChildren.remove(child.restorationId) == child) { _rawChildren.remove(child.restorationId); @@ -901,7 +885,6 @@ class RestorationBucket { } void _addChildData(RestorationBucket child) { - assert(child != null); assert(child._parent == this); if (_claimedChildren.containsKey(child.restorationId)) { // Delay addition until the end of the frame in the hopes that the current @@ -944,7 +927,6 @@ class RestorationBucket { /// another ID, or has moved it to a new parent via [adoptChild]. void rename(String newRestorationId) { assert(_debugAssertNotDisposed()); - assert(newRestorationId != null); if (newRestorationId == restorationId) { return; } diff --git a/packages/flutter/lib/src/services/spell_check.dart b/packages/flutter/lib/src/services/spell_check.dart index 4ca29d283cb..3f7082975a9 100644 --- a/packages/flutter/lib/src/services/spell_check.dart +++ b/packages/flutter/lib/src/services/spell_check.dart @@ -27,9 +27,7 @@ class SuggestionSpan { /// /// The [range] and replacement [suggestions] must all not /// be null. - const SuggestionSpan(this.range, this.suggestions) - : assert(range != null), - assert(suggestions != null); + const SuggestionSpan(this.range, this.suggestions); /// The misspelled range of text. final TextRange range; @@ -58,9 +56,7 @@ class SuggestionSpan { @immutable class SpellCheckResults { /// Creates results based off those received by spell checking some text input. - const SpellCheckResults(this.spellCheckedText, this.suggestionSpans) - : assert(spellCheckedText != null), - assert(suggestionSpans != null); + const SpellCheckResults(this.spellCheckedText, this.suggestionSpans); /// The text that the [suggestionSpans] correspond to. final String spellCheckedText; @@ -170,8 +166,6 @@ class DefaultSpellCheckService implements SpellCheckService { @override Future?> fetchSpellCheckSuggestions( Locale locale, String text) async { - assert(locale != null); - assert(text != null); final List rawResults; final String languageTag = locale.toLanguageTag(); diff --git a/packages/flutter/lib/src/services/system_chrome.dart b/packages/flutter/lib/src/services/system_chrome.dart index f97c14bdd74..a8bab279a82 100644 --- a/packages/flutter/lib/src/services/system_chrome.dart +++ b/packages/flutter/lib/src/services/system_chrome.dart @@ -577,7 +577,6 @@ class SystemChrome { /// /// * [AnnotatedRegion], the widget used to place data into the layer tree. static void setSystemUIOverlayStyle(SystemUiOverlayStyle style) { - assert(style != null); if (_pendingStyle != null) { // The microtask has already been queued; just update the pending value. _pendingStyle = style; diff --git a/packages/flutter/lib/src/services/text_editing_delta.dart b/packages/flutter/lib/src/services/text_editing_delta.dart index 090de35e1bd..3357a7da343 100644 --- a/packages/flutter/lib/src/services/text_editing_delta.dart +++ b/packages/flutter/lib/src/services/text_editing_delta.dart @@ -64,9 +64,7 @@ abstract class TextEditingDelta with Diagnosticable { required this.oldText, required this.selection, required this.composing, - }) : assert(oldText != null), - assert(selection != null), - assert(composing != null); + }); /// Creates an instance of this class from a JSON object by inferring the /// type of delta based on values sent from the engine. diff --git a/packages/flutter/lib/src/services/text_formatter.dart b/packages/flutter/lib/src/services/text_formatter.dart index 8ba5d0d778b..a822b5c8aea 100644 --- a/packages/flutter/lib/src/services/text_formatter.dart +++ b/packages/flutter/lib/src/services/text_formatter.dart @@ -121,8 +121,7 @@ typedef TextInputFormatFunction = TextEditingValue Function( /// Wiring for [TextInputFormatter.withFunction]. class _SimpleTextInputFormatter extends TextInputFormatter { - _SimpleTextInputFormatter(this.formatFunction) - : assert(formatFunction != null); + _SimpleTextInputFormatter(this.formatFunction); final TextInputFormatFunction formatFunction; @@ -271,9 +270,7 @@ class FilteringTextInputFormatter extends TextInputFormatter { this.filterPattern, { required this.allow, this.replacementString = '', - }) : assert(filterPattern != null), - assert(allow != null), - assert(replacementString != null); + }); /// Creates a formatter that only allows characters matching a pattern. /// diff --git a/packages/flutter/lib/src/services/text_input.dart b/packages/flutter/lib/src/services/text_input.dart index 3506da6a1b0..b346660f125 100644 --- a/packages/flutter/lib/src/services/text_input.dart +++ b/packages/flutter/lib/src/services/text_input.dart @@ -478,17 +478,8 @@ class TextInputConfiguration { this.autofillConfiguration = AutofillConfiguration.disabled, this.enableIMEPersonalizedLearning = true, this.enableDeltaModel = false, - }) : assert(inputType != null), - assert(obscureText != null), - smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), - smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled), - assert(autocorrect != null), - assert(enableSuggestions != null), - assert(keyboardAppearance != null), - assert(inputAction != null), - assert(textCapitalization != null), - assert(enableIMEPersonalizedLearning != null), - assert(enableDeltaModel != null); + }) : smartDashesType = smartDashesType ?? (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled), + smartQuotesType = smartQuotesType ?? (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled); /// The type of information for which to optimize the text input control. final TextInputType inputType; @@ -746,8 +737,7 @@ class RawFloatingCursorPoint { RawFloatingCursorPoint({ this.offset, required this.state, - }) : assert(state != null), - assert(state != FloatingCursorDragState.Update || offset != null); + }) : assert(state != FloatingCursorDragState.Update || offset != null); /// The raw position of the floating cursor as determined by the iOS sdk. final Offset? offset; @@ -773,13 +763,7 @@ class TextEditingValue { this.text = '', this.selection = const TextSelection.collapsed(offset: -1), this.composing = TextRange.empty, - }) : assert(text != null), - // The constructor does not verify that `selection` and `composing` are - // valid ranges within `text`, and is unable to do so due to limitation - // of const constructors. Some checks are performed by assertion in - // other occasions. See `_textRangeIsValid`. - assert(selection != null), - assert(composing != null); + }); /// Creates an instance of this class from a JSON object. factory TextEditingValue.fromJSON(Map encoded) { @@ -1300,8 +1284,7 @@ mixin DeltaTextInputClient implements TextInputClient { /// the system's text input using a [TextInputConnection]. class TextInputConnection { TextInputConnection._(this._client) - : assert(_client != null), - _id = _nextId++; + : _id = _nextId++; Size? _cachedSize; Matrix4? _cachedTransform; @@ -1318,7 +1301,6 @@ class TextInputConnection { /// application code will likely break text input for the application. @visibleForTesting static void debugResetId({int to = 1}) { - assert(to != null); assert(() { _nextId = to; return true; @@ -1395,7 +1377,6 @@ class TextInputConnection { /// This information is used for positioning the IME candidates menu on each /// platform. void setComposingRect(Rect rect) { - assert(rect != null); if (rect == _cachedRect) { return; } @@ -1407,7 +1388,6 @@ class TextInputConnection { /// Sends the coordinates of caret rect. This is used on macOS for positioning /// the accent selection menu. void setCaretRect(Rect rect) { - assert(rect != null); if (rect == _cachedCaretRect) { return; } @@ -1515,7 +1495,6 @@ FloatingCursorDragState _toTextCursorAction(String state) { } RawFloatingCursorPoint _toTextPoint(FloatingCursorDragState state, Map encoded) { - assert(state != null, 'You must provide a state to set a new editing point.'); assert(encoded['X'] != null, 'You must provide a value for the horizontal location of the floating cursor.'); assert(encoded['Y'] != null, 'You must provide a value for the vertical location of the floating cursor.'); final Offset offset = state == FloatingCursorDragState.Update @@ -1699,8 +1678,6 @@ class TextInput { /// should call [TextInputConnection.close] on the returned /// [TextInputConnection]. static TextInputConnection attach(TextInputClient client, TextInputConfiguration configuration) { - assert(client != null); - assert(configuration != null); final TextInputConnection connection = TextInputConnection._(client); _instance._attach(connection, configuration); return connection; @@ -1710,9 +1687,6 @@ class TextInput { // by [attach] and by [_handleTextInputInvocation] for the // `TextInputClient.requestExistingInputState` method. void _attach(TextInputConnection connection, TextInputConfiguration configuration) { - assert(connection != null); - assert(connection._client != null); - assert(configuration != null); assert(_debugEnsureInputActionWorksOnPlatform(configuration.inputAction)); _currentConnection = connection; _currentConfiguration = configuration; @@ -1806,7 +1780,6 @@ class TextInput { // The requestExistingInputState request needs to be handled regardless of // the client ID, as long as we have a _currentConnection. if (method == 'TextInputClient.requestExistingInputState') { - assert(_currentConnection!._client != null); _attach(_currentConnection!, _currentConfiguration); final TextEditingValue? editingValue = _currentConnection!._client.currentTextEditingValue; if (editingValue != null) { @@ -1820,7 +1793,6 @@ class TextInput { // The updateEditingStateWithTag request (autofill) can come up even to a // text field that doesn't have a connection. if (method == 'TextInputClient.updateEditingStateWithTag') { - assert(_currentConnection!._client != null); final TextInputClient client = _currentConnection!._client; final AutofillScope? scope = client.currentAutofillScope; final Map editingValue = args[1] as Map; @@ -1951,14 +1923,12 @@ class TextInput { } void _updateConfig(TextInputConfiguration configuration) { - assert(configuration != null); for (final TextInputControl control in _inputControls) { control.updateConfig(configuration); } } void _setEditingState(TextEditingValue value) { - assert(value != null); for (final TextInputControl control in _inputControls) { control.setEditingState(value); } @@ -2094,7 +2064,6 @@ class TextInput { /// * [AutofillGroup.onDisposeAction], a configurable action that runs when a /// topmost [AutofillGroup] is getting disposed. static void finishAutofillContext({ bool shouldSave = true }) { - assert(shouldSave != null); for (final TextInputControl control in TextInput._instance._inputControls) { control.finishAutofillContext(shouldSave: shouldSave); }