Unverified Commit 608b03c7 authored by Dan Field's avatar Dan Field Committed by GitHub

Update docs for ancestorWidgetOfExactType (#28675)

* doc update
parent d4474128
......@@ -488,6 +488,12 @@ class _LicensePageState extends State<LicensePage> {
}
String _defaultApplicationName(BuildContext context) {
// This doesn't handle the case of the application's title dynamically
// changing. In theory, we should make Title expose the current application
// title using an InheritedWidget, and so forth. However, in practice, if
// someone really wants their application title to change dynamically, they
// can provide an explicit applicationName to the widgets defined in this
// file, instead of relying on the default.
final Title ancestorTitle = context.ancestorWidgetOfExactType(Title);
return ancestorTitle?.title ?? Platform.resolvedExecutable.split(Platform.pathSeparator).last;
}
......
......@@ -1942,11 +1942,15 @@ abstract class BuildContext {
/// Returns the nearest ancestor widget of the given type, which must be the
/// type of a concrete [Widget] subclass.
///
/// This should not be used from build methods, because the build context will
/// not be rebuilt if the value that would be returned by this method changes.
/// In general, [inheritFromWidgetOfExactType] is more useful. This method is
/// In general, [inheritFromWidgetOfExactType] is more useful, since inherited
/// widgets will trigger consumers to rebuild when they change. This method is
/// appropriate when used in interaction event handlers (e.g. gesture
/// callbacks), or for performing one-off tasks.
/// callbacks) or for performing one-off tasks such as asserting that you have
/// or don't have a widget of a specific type as an ancestor. The return value
/// of a Widget's build method should not depend on the value returned by this
/// method, because the build context will not rebuild if the return value of
/// this method changes. This could lead to a situation where data used in the
/// build method changes, but the widget is not rebuilt.
///
/// Calling this method is relatively expensive (O(N) in the depth of the
/// tree). Only call this method if the distance from this widget to the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment