pub struct BuildContext<'a> {
pub element_id: ElementId,
/* private fields */
}Expand description
BuildContext — state.build() 的参数,提供 depend_on + 主题/方向/Locale 访问。
生命周期:ctx 由 ElementTree::children_with_positions_of 在 build 前构造,
build 后立即 drop,生命周期不长于 build 调用栈。
Fields§
§element_id: ElementId当前 build 的 element id
Implementations§
Source§impl<'a> BuildContext<'a>
impl<'a> BuildContext<'a>
Sourcepub fn depend_on<T: InheritedWidget>(&mut self) -> &T
pub fn depend_on<T: InheritedWidget>(&mut self) -> &T
沿 ancestor 链找最近的 T 类型 InheritedElement,返回其 widget 引用 + 注册 dependent。
Sourcepub fn try_theme_rc(&mut self) -> Option<Rc<ThemeData>>
pub fn try_theme_rc(&mut self) -> Option<Rc<ThemeData>>
便捷方法 — 拿 ThemeData + 注册依赖;没有 ThemeWidget 祖先时返回 None
(不会 panic)。返回 Rc 共享引用:State 缓存主题时零拷贝。
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for BuildContext<'a>
impl<'a> !Send for BuildContext<'a>
impl<'a> !Sync for BuildContext<'a>
impl<'a> !UnwindSafe for BuildContext<'a>
impl<'a> Forget for BuildContext<'a>
impl<'a> Freeze for BuildContext<'a>
impl<'a> Move for BuildContext<'a>
impl<'a> Unpin for BuildContext<'a>
impl<'a> UnsafeUnpin for BuildContext<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more