Skip to content

Commit aad941e

Browse files
authored
Avoid using FlutterError.fromParts when possible (flutter#43696)
This PR is a follow up of flutter#42640 Some changes of that PR includes redundant changes using FlutterError.fromParts constructor even though it's not necessary. Some minor changes are: - Remove one unnecessary todo - Fix indent consistencies
1 parent d030296 commit aad941e

File tree

13 files changed

+93
-117
lines changed

13 files changed

+93
-117
lines changed

packages/flutter/lib/src/animation/animations.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,12 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
439439
final double transformedValue = activeCurve.transform(t);
440440
final double roundedTransformedValue = transformedValue.round().toDouble();
441441
if (roundedTransformedValue != t) {
442-
throw FlutterError.fromParts(<DiagnosticsNode>[
443-
ErrorSummary('Invalid curve endpoint at $t.'),
444-
ErrorDescription(
445-
'Curves must map 0.0 to near zero and 1.0 to near one but '
446-
'${activeCurve.runtimeType} mapped $t to $transformedValue, which '
447-
'is near $roundedTransformedValue.'
448-
)
449-
]);
442+
throw FlutterError(
443+
'Invalid curve endpoint at $t.\n'
444+
'Curves must map 0.0 to near zero and 1.0 to near one but '
445+
'${activeCurve.runtimeType} mapped $t to $transformedValue, which '
446+
'is near $roundedTransformedValue.'
447+
);
450448
}
451449
return true;
452450
}());

packages/flutter/lib/src/cupertino/tab_view.dart

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,33 +192,29 @@ class _CupertinoTabViewState extends State<CupertinoTabView> {
192192
Route<dynamic> _onUnknownRoute(RouteSettings settings) {
193193
assert(() {
194194
if (widget.onUnknownRoute == null) {
195-
throw FlutterError.fromParts(<DiagnosticsNode>[
196-
ErrorSummary('Could not find a generator for route $settings in the $runtimeType.'),
197-
ErrorDescription(
198-
'Generators for routes are searched for in the following order:\n'
199-
' 1. For the "/" route, the "builder" property, if non-null, is used.\n'
200-
' 2. Otherwise, the "routes" table is used, if it has an entry for '
201-
'the route.\n'
202-
' 3. Otherwise, onGenerateRoute is called. It should return a '
203-
'non-null value for any valid route not handled by "builder" and "routes".\n'
204-
' 4. Finally if all else fails onUnknownRoute is called.\n'
205-
'Unfortunately, onUnknownRoute was not set.'
206-
)
207-
]);
195+
throw FlutterError(
196+
'Could not find a generator for route $settings in the $runtimeType.\n'
197+
'Generators for routes are searched for in the following order:\n'
198+
' 1. For the "/" route, the "builder" property, if non-null, is used.\n'
199+
' 2. Otherwise, the "routes" table is used, if it has an entry for '
200+
'the route.\n'
201+
' 3. Otherwise, onGenerateRoute is called. It should return a '
202+
'non-null value for any valid route not handled by "builder" and "routes".\n'
203+
' 4. Finally if all else fails onUnknownRoute is called.\n'
204+
'Unfortunately, onUnknownRoute was not set.'
205+
);
208206
}
209207
return true;
210208
}());
211209
final Route<dynamic> result = widget.onUnknownRoute(settings);
212210
assert(() {
213211
if (result == null) {
214-
throw FlutterError.fromParts(<DiagnosticsNode>[
215-
ErrorSummary('The onUnknownRoute callback returned null.'),
216-
ErrorDescription(
217-
'When the $runtimeType requested the route $settings from its '
218-
'onUnknownRoute callback, the callback returned null. Such callbacks '
219-
'must never return null.'
220-
)
221-
]);
212+
throw FlutterError(
213+
'The onUnknownRoute callback returned null.\n'
214+
'When the $runtimeType requested the route $settings from its '
215+
'onUnknownRoute callback, the callback returned null. Such callbacks '
216+
'must never return null.'
217+
);
222218
}
223219
return true;
224220
}());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ class ChangeNotifier implements Listenable {
102102
bool _debugAssertNotDisposed() {
103103
assert(() {
104104
if (_listeners == null) {
105-
throw FlutterError.fromParts(<DiagnosticsNode>[
106-
ErrorSummary('A $runtimeType was used after being disposed.'),
107-
ErrorDescription('Once you have called dispose() on a $runtimeType, it can no longer be used.')
108-
]);
105+
throw FlutterError(
106+
'A $runtimeType was used after being disposed.\n'
107+
'Once you have called dispose() on a $runtimeType, it can no longer be used.'
108+
);
109109
}
110110
return true;
111111
}());

packages/flutter/lib/src/material/page.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class MaterialPageRoute<T> extends PageRoute<T> {
8282
final Widget result = builder(context);
8383
assert(() {
8484
if (result == null) {
85-
throw FlutterError.fromParts(<DiagnosticsNode>[
86-
ErrorSummary('The builder for route "${settings.name}" returned null.'),
87-
ErrorDescription('Route builders must never return null.')
88-
]);
85+
throw FlutterError(
86+
'The builder for route "${settings.name}" returned null.\n'
87+
'Route builders must never return null.'
88+
);
8989
}
9090
return true;
9191
}());

packages/flutter/lib/src/rendering/custom_layout.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,16 @@ abstract class MultiChildLayoutDelegate {
142142
final RenderBox child = _idToChild[childId];
143143
assert(() {
144144
if (child == null) {
145-
throw FlutterError.fromParts(<DiagnosticsNode>[
146-
ErrorSummary('The $this custom multichild layout delegate tried to lay out a non-existent child.'),
147-
ErrorDescription('There is no child with the id "$childId".')
148-
]);
145+
throw FlutterError(
146+
'The $this custom multichild layout delegate tried to lay out a non-existent child.\n'
147+
'There is no child with the id "$childId".'
148+
);
149149
}
150150
if (!_debugChildrenNeedingLayout.remove(child)) {
151-
throw FlutterError.fromParts(<DiagnosticsNode>[
152-
ErrorSummary('The $this custom multichild layout delegate tried to lay out the child with id "$childId" more than once.'),
153-
ErrorDescription('Each child must be laid out exactly once.')
154-
]);
151+
throw FlutterError(
152+
'The $this custom multichild layout delegate tried to lay out the child with id "$childId" more than once.\n'
153+
'Each child must be laid out exactly once.'
154+
);
155155
}
156156
try {
157157
assert(constraints.debugAssertIsValid(isAppliedConstraint: true));
@@ -182,15 +182,15 @@ abstract class MultiChildLayoutDelegate {
182182
final RenderBox child = _idToChild[childId];
183183
assert(() {
184184
if (child == null) {
185-
throw FlutterError.fromParts(<DiagnosticsNode>[
186-
ErrorSummary('The $this custom multichild layout delegate tried to position out a non-existent child:'),
187-
ErrorDescription('There is no child with the id "$childId".')
188-
]);
185+
throw FlutterError(
186+
'The $this custom multichild layout delegate tried to position out a non-existent child:\n'
187+
'There is no child with the id "$childId".'
188+
);
189189
}
190190
if (offset == null) {
191-
throw FlutterError.fromParts(<DiagnosticsNode>[
192-
ErrorSummary('The $this custom multichild layout delegate provided a null position for the child with id "$childId".')
193-
]);
191+
throw FlutterError(
192+
'The $this custom multichild layout delegate provided a null position for the child with id "$childId".'
193+
);
194194
}
195195
return true;
196196
}());

packages/flutter/lib/src/rendering/flow.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,11 @@ class RenderFlow extends RenderBox
318318
final FlowParentData childParentData = child.parentData as FlowParentData;
319319
assert(() {
320320
if (childParentData._transform != null) {
321-
throw FlutterError.fromParts(<DiagnosticsNode>[
322-
ErrorSummary('Cannot call paintChild twice for the same child.'),
323-
ErrorDescription(
324-
'The flow delegate of type ${_delegate.runtimeType} attempted to '
325-
'paint child $i multiple times, which is not permitted.'
326-
)
327-
]);
321+
throw FlutterError(
322+
'Cannot call paintChild twice for the same child.\n'
323+
'The flow delegate of type ${_delegate.runtimeType} attempted to '
324+
'paint child $i multiple times, which is not permitted.'
325+
);
328326
}
329327
return true;
330328
}());

packages/flutter/lib/src/rendering/proxy_box.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,13 @@ class RenderAspectRatio extends RenderProxyBox {
461461
assert(constraints.debugAssertIsValid());
462462
assert(() {
463463
if (!constraints.hasBoundedWidth && !constraints.hasBoundedHeight) {
464-
throw FlutterError.fromParts(<DiagnosticsNode>[
465-
ErrorSummary('$runtimeType has unbounded constraints.'),
466-
ErrorDescription(
467-
'This $runtimeType was given an aspect ratio of $aspectRatio but was given '
468-
'both unbounded width and unbounded height constraints. Because both '
469-
"constraints were unbounded, this render object doesn't know how much "
470-
'size to consume.'
471-
)
472-
]);
464+
throw FlutterError(
465+
'$runtimeType has unbounded constraints.\n'
466+
'This $runtimeType was given an aspect ratio of $aspectRatio but was given '
467+
'both unbounded width and unbounded height constraints. Because both '
468+
'constraints were unbounded, this render object doesn\'t know how much '
469+
'size to consume.'
470+
);
473471
}
474472
return true;
475473
}());

packages/flutter/lib/src/widgets/app.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,14 +1018,12 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
10181018
final Route<dynamic> result = widget.onUnknownRoute(settings);
10191019
assert(() {
10201020
if (result == null) {
1021-
throw FlutterError.fromParts(<DiagnosticsNode>[
1022-
ErrorSummary('The onUnknownRoute callback returned null.'),
1023-
ErrorDescription(
1024-
'When the $runtimeType requested the route $settings from its '
1025-
'onUnknownRoute callback, the callback returned null. Such callbacks '
1026-
'must never return null.'
1027-
)
1028-
]);
1021+
throw FlutterError(
1022+
'The onUnknownRoute callback returned null.\n'
1023+
'When the $runtimeType requested the route $settings from its '
1024+
'onUnknownRoute callback, the callback returned null. Such callbacks '
1025+
'must never return null.'
1026+
);
10291027
}
10301028
return true;
10311029
}());

packages/flutter/lib/src/widgets/debug.dart

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,11 @@ bool debugChildrenHaveDuplicateKeys(Widget parent, Iterable<Widget> children) {
136136
assert(() {
137137
final Key nonUniqueKey = _firstNonUniqueKey(children);
138138
if (nonUniqueKey != null) {
139-
throw FlutterError.fromParts(<DiagnosticsNode>[
140-
ErrorSummary('Duplicate keys found.'),
141-
ErrorDescription(
142-
'If multiple keyed nodes exist as children of another node, they must have unique keys.\n'
143-
'$parent has multiple children with key $nonUniqueKey.'
144-
),
145-
]);
139+
throw FlutterError(
140+
'Duplicate keys found.\n'
141+
'If multiple keyed nodes exist as children of another node, they must have unique keys.\n'
142+
'$parent has multiple children with key $nonUniqueKey.'
143+
);
146144
}
147145
return true;
148146
}());
@@ -165,9 +163,7 @@ bool debugItemsHaveDuplicateKeys(Iterable<Widget> items) {
165163
assert(() {
166164
final Key nonUniqueKey = _firstNonUniqueKey(items);
167165
if (nonUniqueKey != null)
168-
throw FlutterError.fromParts(<DiagnosticsNode>[
169-
ErrorSummary('Duplicate key found: $nonUniqueKey.'),
170-
]);
166+
throw FlutterError('Duplicate key found: $nonUniqueKey.');
171167
return true;
172168
}());
173169
return false;
@@ -315,7 +311,7 @@ bool debugAssertAllWidgetVarsUnset(String reason) {
315311
debugPrintGlobalKeyedWidgetLifecycle ||
316312
debugProfileBuildsEnabled ||
317313
debugHighlightDeprecatedWidgets) {
318-
throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary(reason)]);
314+
throw FlutterError(reason);
319315
}
320316
return true;
321317
}());

packages/flutter/lib/src/widgets/editable_text.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class TextEditingController extends ValueNotifier<TextEditingValue> {
190190
/// change the controller's [value].
191191
set selection(TextSelection newSelection) {
192192
if (newSelection.start > text.length || newSelection.end > text.length)
193-
throw FlutterError.fromParts(<DiagnosticsNode>[ErrorSummary('invalid text selection: $newSelection')]);
193+
throw FlutterError('invalid text selection: $newSelection');
194194
value = value.copyWith(selection: newSelection, composing: TextRange.empty);
195195
}
196196

0 commit comments

Comments
 (0)