mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

* Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs
62 lines
1.9 KiB
Dart
62 lines
1.9 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
/// Provides an iterable that efficiently returns all the elements
|
|
/// rooted at the given element. See [CachingIterable] for details.
|
|
///
|
|
/// This method must be called again if the tree changes. You cannot
|
|
/// call this function once, then reuse the iterable after having
|
|
/// changed the state of the tree, because the iterable returned by
|
|
/// this function caches the results and only walks the tree once.
|
|
///
|
|
/// The same applies to any iterable obtained indirectly through this
|
|
/// one, for example the results of calling `where` on this iterable
|
|
/// are also cached.
|
|
Iterable<Element> collectAllElementsFrom(
|
|
Element rootElement, {
|
|
@required bool skipOffstage,
|
|
}) {
|
|
return CachingIterable<Element>(_DepthFirstChildIterator(rootElement, skipOffstage));
|
|
}
|
|
|
|
class _DepthFirstChildIterator implements Iterator<Element> {
|
|
_DepthFirstChildIterator(Element rootElement, this.skipOffstage)
|
|
: _stack = _reverseChildrenOf(rootElement, skipOffstage).toList();
|
|
|
|
final bool skipOffstage;
|
|
|
|
Element _current;
|
|
|
|
final List<Element> _stack;
|
|
|
|
@override
|
|
Element get current => _current;
|
|
|
|
@override
|
|
bool moveNext() {
|
|
if (_stack.isEmpty)
|
|
return false;
|
|
|
|
_current = _stack.removeLast();
|
|
// Stack children in reverse order to traverse first branch first
|
|
_stack.addAll(_reverseChildrenOf(_current, skipOffstage));
|
|
|
|
return true;
|
|
}
|
|
|
|
static Iterable<Element> _reverseChildrenOf(Element element, bool skipOffstage) {
|
|
assert(element != null);
|
|
final List<Element> children = <Element>[];
|
|
if (skipOffstage) {
|
|
element.debugVisitOnstageChildren(children.add);
|
|
} else {
|
|
element.visitChildren(children.add);
|
|
}
|
|
return children.reversed;
|
|
}
|
|
}
|