Prefer .of to .from (#94772)
This commit is contained in:
parent
ac6b5951ad
commit
e4a1d3e1d3
@ -137,7 +137,7 @@ mixin AnimationLocalListenersMixin {
|
||||
@protected
|
||||
@pragma('vm:notify-debugger-on-exception')
|
||||
void notifyListeners() {
|
||||
final List<VoidCallback> localListeners = List<VoidCallback>.from(_listeners);
|
||||
final List<VoidCallback> localListeners = List<VoidCallback>.of(_listeners);
|
||||
for (final VoidCallback listener in localListeners) {
|
||||
InformationCollector? collector;
|
||||
assert(() {
|
||||
@ -226,7 +226,7 @@ mixin AnimationLocalStatusListenersMixin {
|
||||
@protected
|
||||
@pragma('vm:notify-debugger-on-exception')
|
||||
void notifyStatusListeners(AnimationStatus status) {
|
||||
final List<AnimationStatusListener> localListeners = List<AnimationStatusListener>.from(_statusListeners);
|
||||
final List<AnimationStatusListener> localListeners = List<AnimationStatusListener>.of(_statusListeners);
|
||||
for (final AnimationStatusListener listener in localListeners) {
|
||||
try {
|
||||
if (_statusListeners.contains(listener))
|
||||
|
@ -159,7 +159,7 @@ class _CupertinoTabViewState extends State<CupertinoTabView> {
|
||||
|
||||
void _updateObservers() {
|
||||
_navigatorObservers =
|
||||
List<NavigatorObserver>.from(widget.navigatorObservers)
|
||||
List<NavigatorObserver>.of(widget.navigatorObservers)
|
||||
..add(_heroController);
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ class CachingIterable<E> extends IterableBase<E> {
|
||||
@override
|
||||
List<E> toList({ bool growable = true }) {
|
||||
_precacheEntireList();
|
||||
return List<E>.from(_results, growable: growable);
|
||||
return List<E>.of(_results, growable: growable);
|
||||
}
|
||||
|
||||
void _precacheEntireList() {
|
||||
|
@ -583,7 +583,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
final List<_TapGesture> localGestures = List<_TapGesture>.from(_gestureMap.values);
|
||||
final List<_TapGesture> localGestures = List<_TapGesture>.of(_gestureMap.values);
|
||||
for (final _TapGesture gesture in localGestures)
|
||||
gesture.cancel();
|
||||
// Rejection of each gesture should cause it to be removed from our map
|
||||
|
@ -118,12 +118,12 @@ class PointerRouter {
|
||||
/// PointerRouter object.
|
||||
void route(PointerEvent event) {
|
||||
final Map<PointerRoute, Matrix4?>? routes = _routeMap[event.pointer];
|
||||
final Map<PointerRoute, Matrix4?> copiedGlobalRoutes = Map<PointerRoute, Matrix4?>.from(_globalRoutes);
|
||||
final Map<PointerRoute, Matrix4?> copiedGlobalRoutes = Map<PointerRoute, Matrix4?>.of(_globalRoutes);
|
||||
if (routes != null) {
|
||||
_dispatchEventToRoutes(
|
||||
event,
|
||||
routes,
|
||||
Map<PointerRoute, Matrix4?>.from(routes),
|
||||
Map<PointerRoute, Matrix4?>.of(routes),
|
||||
);
|
||||
}
|
||||
_dispatchEventToRoutes(event, _globalRoutes, copiedGlobalRoutes);
|
||||
|
@ -300,7 +300,7 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
|
||||
@protected
|
||||
@mustCallSuper
|
||||
void resolve(GestureDisposition disposition) {
|
||||
final List<GestureArenaEntry> localEntries = List<GestureArenaEntry>.from(_entries.values);
|
||||
final List<GestureArenaEntry> localEntries = List<GestureArenaEntry>.of(_entries.values);
|
||||
_entries.clear();
|
||||
for (final GestureArenaEntry entry in localEntries)
|
||||
entry.resolve(disposition);
|
||||
|
@ -1360,8 +1360,8 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
|
||||
// otherwise, no explicit type adding items maybe trigger a crash/failure
|
||||
// when hint and selectedItemBuilder are provided.
|
||||
final List<Widget> items = widget.selectedItemBuilder == null
|
||||
? (widget.items != null ? List<Widget>.from(widget.items!) : <Widget>[])
|
||||
: List<Widget>.from(widget.selectedItemBuilder!(context));
|
||||
? (widget.items != null ? List<Widget>.of(widget.items!) : <Widget>[])
|
||||
: List<Widget>.of(widget.selectedItemBuilder!(context));
|
||||
|
||||
int? hintIndex;
|
||||
if (widget.hint != null || (!_enabled && widget.disabledHint != null)) {
|
||||
|
@ -168,7 +168,7 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_children = List<MergeableMaterialItem>.from(widget.children);
|
||||
_children = List<MergeableMaterialItem>.of(widget.children);
|
||||
|
||||
for (int i = 0; i < _children.length; i += 1) {
|
||||
final MergeableMaterialItem child = _children[i];
|
||||
|
@ -1419,7 +1419,7 @@ class _TabBarViewState extends State<TabBarView> {
|
||||
setState(() {
|
||||
_warpUnderwayCount += 1;
|
||||
|
||||
_childrenWithKey = List<Widget>.from(_childrenWithKey, growable: false);
|
||||
_childrenWithKey = List<Widget>.of(_childrenWithKey, growable: false);
|
||||
final Widget temp = _childrenWithKey[initialPage];
|
||||
_childrenWithKey[initialPage] = _childrenWithKey[previousIndex];
|
||||
_childrenWithKey[previousIndex] = temp;
|
||||
|
@ -627,7 +627,7 @@ abstract class ImageStreamCompleter with Diagnosticable {
|
||||
return;
|
||||
// Make a copy to allow for concurrent modification.
|
||||
final List<ImageStreamListener> localListeners =
|
||||
List<ImageStreamListener>.from(_listeners);
|
||||
List<ImageStreamListener>.of(_listeners);
|
||||
for (final ImageStreamListener listener in localListeners) {
|
||||
try {
|
||||
listener.onImage(image.clone(), false);
|
||||
|
@ -647,7 +647,7 @@ class RenderTable extends RenderBox {
|
||||
// update our internal values
|
||||
_columns = columns;
|
||||
_rows = cells.length ~/ columns;
|
||||
_children = List<RenderBox?>.from(cells);
|
||||
_children = List<RenderBox?>.of(cells);
|
||||
assert(_children.length == rows * columns);
|
||||
markNeedsLayout();
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ mixin SchedulerBinding on BindingBase {
|
||||
@pragma('vm:notify-debugger-on-exception')
|
||||
void _executeTimingsCallbacks(List<FrameTiming> timings) {
|
||||
final List<TimingsCallback> clonedCallbacks =
|
||||
List<TimingsCallback>.from(_timingsCallbacks);
|
||||
List<TimingsCallback>.of(_timingsCallbacks);
|
||||
for (final TimingsCallback callback in clonedCallbacks) {
|
||||
try {
|
||||
if (_timingsCallbacks.contains(callback)) {
|
||||
@ -562,7 +562,7 @@ mixin SchedulerBinding on BindingBase {
|
||||
// even if the information collector is called after
|
||||
// the problem has been resolved.
|
||||
final int count = transientCallbackCount;
|
||||
final Map<int, _FrameCallbackEntry> callbacks = Map<int, _FrameCallbackEntry>.from(_transientCallbacks);
|
||||
final Map<int, _FrameCallbackEntry> callbacks = Map<int, _FrameCallbackEntry>.of(_transientCallbacks);
|
||||
FlutterError.reportError(FlutterErrorDetails(
|
||||
exception: reason,
|
||||
library: 'scheduler library',
|
||||
@ -1084,7 +1084,7 @@ mixin SchedulerBinding on BindingBase {
|
||||
// POST-FRAME CALLBACKS
|
||||
_schedulerPhase = SchedulerPhase.postFrameCallbacks;
|
||||
final List<FrameCallback> localPostFrameCallbacks =
|
||||
List<FrameCallback>.from(_postFrameCallbacks);
|
||||
List<FrameCallback>.of(_postFrameCallbacks);
|
||||
_postFrameCallbacks.clear();
|
||||
for (final FrameCallback callback in localPostFrameCallbacks)
|
||||
_invokeFrameCallback(callback, _currentFrameTimeStamp!);
|
||||
|
@ -217,7 +217,7 @@ class AttributedString {
|
||||
|
||||
// None of the strings is empty.
|
||||
final String newString = string + other.string;
|
||||
final List<StringAttribute> newAttributes = List<StringAttribute>.from(attributes);
|
||||
final List<StringAttribute> newAttributes = List<StringAttribute>.of(attributes);
|
||||
if (other.attributes.isNotEmpty) {
|
||||
final int offset = string.length;
|
||||
for (final StringAttribute attribute in other.attributes) {
|
||||
@ -1739,7 +1739,7 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin {
|
||||
}
|
||||
assert(!newChildren.any((SemanticsNode node) => node.isMergedIntoParent) || isPartOfNodeMerging);
|
||||
|
||||
_debugPreviousSnapshot = List<SemanticsNode>.from(newChildren);
|
||||
_debugPreviousSnapshot = List<SemanticsNode>.of(newChildren);
|
||||
|
||||
SemanticsNode ancestor = this;
|
||||
while (ancestor.parent is SemanticsNode)
|
||||
@ -2262,8 +2262,8 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin {
|
||||
_flags = config._flags;
|
||||
_textDirection = config.textDirection;
|
||||
_sortKey = config.sortKey;
|
||||
_actions = Map<SemanticsAction, SemanticsActionHandler>.from(config._actions);
|
||||
_customSemanticsActions = Map<CustomSemanticsAction, VoidCallback>.from(config._customSemanticsActions);
|
||||
_actions = Map<SemanticsAction, SemanticsActionHandler>.of(config._actions);
|
||||
_customSemanticsActions = Map<CustomSemanticsAction, VoidCallback>.of(config._customSemanticsActions);
|
||||
_actionsAsBits = config._actionsAsBits;
|
||||
_textSelection = config._textSelection;
|
||||
_isMultiline = config.isMultiline;
|
||||
@ -2304,7 +2304,7 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin {
|
||||
AttributedString attributedDecreasedValue = _attributedDecreasedValue;
|
||||
AttributedString attributedHint = _attributedHint;
|
||||
TextDirection? textDirection = _textDirection;
|
||||
Set<SemanticsTag>? mergedTags = tags == null ? null : Set<SemanticsTag>.from(tags!);
|
||||
Set<SemanticsTag>? mergedTags = tags == null ? null : Set<SemanticsTag>.of(tags!);
|
||||
TextSelection? textSelection = _textSelection;
|
||||
int? scrollChildCount = _scrollChildCount;
|
||||
int? scrollIndex = _scrollIndex;
|
||||
|
@ -672,7 +672,7 @@ class RawKeyboard {
|
||||
'${event.data}',
|
||||
);
|
||||
// Send the event to passive listeners.
|
||||
for (final ValueChanged<RawKeyEvent> listener in List<ValueChanged<RawKeyEvent>>.from(_listeners)) {
|
||||
for (final ValueChanged<RawKeyEvent> listener in List<ValueChanged<RawKeyEvent>>.of(_listeners)) {
|
||||
try {
|
||||
if (_listeners.contains(listener)) {
|
||||
listener(event);
|
||||
|
@ -341,7 +341,7 @@ abstract class Action<T extends Intent> with Diagnosticable {
|
||||
|
||||
// Make a local copy so that a listener can unregister while the list is
|
||||
// being iterated over.
|
||||
final List<ActionListenerCallback> localListeners = List<ActionListenerCallback>.from(_listeners);
|
||||
final List<ActionListenerCallback> localListeners = List<ActionListenerCallback>.of(_listeners);
|
||||
for (final ActionListenerCallback listener in localListeners) {
|
||||
InformationCollector? collector;
|
||||
assert(() {
|
||||
|
@ -635,7 +635,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
|
||||
/// [SystemChannels.navigation].
|
||||
@protected
|
||||
Future<void> handlePopRoute() async {
|
||||
for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.from(_observers)) {
|
||||
for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) {
|
||||
if (await observer.didPopRoute())
|
||||
return;
|
||||
}
|
||||
@ -655,14 +655,14 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
|
||||
@protected
|
||||
@mustCallSuper
|
||||
Future<void> handlePushRoute(String route) async {
|
||||
for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.from(_observers)) {
|
||||
for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) {
|
||||
if (await observer.didPushRoute(route))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handlePushRouteInformation(Map<dynamic, dynamic> routeArguments) async {
|
||||
for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.from(_observers)) {
|
||||
for (final WidgetsBindingObserver observer in List<WidgetsBindingObserver>.of(_observers)) {
|
||||
if (
|
||||
await observer.didPushRouteInformation(
|
||||
RouteInformation(
|
||||
|
@ -1511,7 +1511,7 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
|
||||
if (_listeners.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final List<ValueChanged<FocusHighlightMode>> localListeners = List<ValueChanged<FocusHighlightMode>>.from(_listeners);
|
||||
final List<ValueChanged<FocusHighlightMode>> localListeners = List<ValueChanged<FocusHighlightMode>>.of(_listeners);
|
||||
for (final ValueChanged<FocusHighlightMode> listener in localListeners) {
|
||||
try {
|
||||
if (_listeners.contains(listener)) {
|
||||
|
@ -1854,7 +1854,7 @@ abstract class MultiChildRenderObjectWidget extends RenderObjectWidget {
|
||||
///
|
||||
/// Widget build(...) {
|
||||
/// // Always create a new list of children as a Widget is immutable.
|
||||
/// return Row(children: List.from(_children));
|
||||
/// return Row(children: List.of(_children));
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@ -5053,7 +5053,7 @@ class InheritedElement extends ProxyElement {
|
||||
assert(_lifecycleState == _ElementLifecycle.active);
|
||||
final Map<Type, InheritedElement>? incomingWidgets = _parent?._inheritedWidgets;
|
||||
if (incomingWidgets != null)
|
||||
_inheritedWidgets = HashMap<Type, InheritedElement>.from(incomingWidgets);
|
||||
_inheritedWidgets = HashMap<Type, InheritedElement>.of(incomingWidgets);
|
||||
else
|
||||
_inheritedWidgets = HashMap<Type, InheritedElement>();
|
||||
_inheritedWidgets![widget.runtimeType] = this;
|
||||
|
@ -448,7 +448,7 @@ class Localizations extends StatefulWidget {
|
||||
assert(context != null);
|
||||
final _LocalizationsScope? scope = context.dependOnInheritedWidgetOfExactType<_LocalizationsScope>();
|
||||
assert(scope != null, 'a Localizations ancestor was not found');
|
||||
return List<LocalizationsDelegate<dynamic>>.from(scope!.localizationsState.widget.delegates);
|
||||
return List<LocalizationsDelegate<dynamic>>.of(scope!.localizationsState.widget.delegates);
|
||||
}
|
||||
|
||||
/// Returns the localized resources object of the given `type` for the widget
|
||||
|
@ -437,7 +437,7 @@ class OverlayState extends State<Overlay> with TickerProviderStateMixin {
|
||||
return;
|
||||
if (listEquals(_entries, newEntriesList))
|
||||
return;
|
||||
final LinkedHashSet<OverlayEntry> old = LinkedHashSet<OverlayEntry>.from(_entries);
|
||||
final LinkedHashSet<OverlayEntry> old = LinkedHashSet<OverlayEntry>.of(_entries);
|
||||
for (final OverlayEntry entry in newEntriesList) {
|
||||
entry._overlay ??= this;
|
||||
}
|
||||
|
@ -1405,7 +1405,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
|
||||
Future<RoutePopDisposition> willPop() async {
|
||||
final _ModalScopeState<T>? scope = _scopeKey.currentState;
|
||||
assert(scope != null);
|
||||
for (final WillPopCallback callback in List<WillPopCallback>.from(_willPopCallbacks)) {
|
||||
for (final WillPopCallback callback in List<WillPopCallback>.of(_willPopCallbacks)) {
|
||||
if (await callback() != true)
|
||||
return RoutePopDisposition.doNotPop;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ class ScrollController extends ChangeNotifier {
|
||||
/// value was out of range.
|
||||
void jumpTo(double value) {
|
||||
assert(_positions.isNotEmpty, 'ScrollController not attached to any scroll views.');
|
||||
for (final ScrollPosition position in List<ScrollPosition>.from(_positions))
|
||||
for (final ScrollPosition position in List<ScrollPosition>.of(_positions))
|
||||
position.jumpTo(value);
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ class ScrollNotificationObserverState extends State<ScrollNotificationObserver>
|
||||
if (_listeners!.isEmpty)
|
||||
return;
|
||||
|
||||
final List<_ListenerEntry> localListeners = List<_ListenerEntry>.from(_listeners!);
|
||||
final List<_ListenerEntry> localListeners = List<_ListenerEntry>.of(_listeners!);
|
||||
for (final _ListenerEntry entry in localListeners) {
|
||||
try {
|
||||
if (entry.list != null)
|
||||
|
@ -167,7 +167,7 @@ class _SharedAppDataState extends State<SharedAppData> {
|
||||
void setValue<K extends Object, V>(K key, V value) {
|
||||
if (data[key] != value) {
|
||||
setState(() {
|
||||
data = Map<Object, Object?>.from(data);
|
||||
data = Map<Object, Object?>.of(data);
|
||||
data[key] = value;
|
||||
});
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class KeySet<T extends KeyboardKey> {
|
||||
: assert(keys != null),
|
||||
assert(keys.isNotEmpty),
|
||||
assert(!keys.contains(null)),
|
||||
_keys = HashSet<T>.from(keys);
|
||||
_keys = HashSet<T>.of(keys);
|
||||
|
||||
/// Returns a copy of the [KeyboardKey]s in this [KeySet].
|
||||
Set<T> get keys => _keys.toSet();
|
||||
|
@ -662,7 +662,7 @@ class SliverChildListDelegate extends SliverChildDelegate {
|
||||
///
|
||||
/// Widget build(BuildContext context) {
|
||||
/// // Always create a new list of children as a Widget is immutable.
|
||||
/// return PageView(children: List<Widget>.from(_children));
|
||||
/// return PageView(children: List<Widget>.of(_children));
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
|
Loading…
x
Reference in New Issue
Block a user