pub struct Visibility {
pub key: Option<KeyRef>,
pub child: WidgetRef,
pub replacement: WidgetRef,
pub visible: bool,
pub maintain_state: bool,
pub maintain_animation: bool,
pub maintain_size: bool,
pub maintain_semantics: bool,
pub maintain_interactivity: bool,
pub maintain_focusability: bool,
}Expand description
Whether to show or hide a child.
By default, the visible property controls whether the
child is included in the subtree or not; when it is not
visible, the replacement child (typically a
zero-sized box) is included instead.
A variety of flags can be used to tweak exactly how the child is hidden.
(Changing the flags dynamically is discouraged, as it can cause the
child subtree to be rebuilt, with any state in the subtree being
discarded. Typically, only the visible flag is changed dynamically.)
These widgets provide some of the facets of this one:
Opacity, which can stop its child from being painted.Offstage, which can stop its child from being laid out or painted.TickerMode, which can stop its child from being animated.ExcludeSemantics, which can hide the child from accessibility tools.IgnorePointer, which can disable touch interactions with the child.
Using this widget is not necessary to hide children. The simplest way to hide a child is
just to not include it, or, if a child must be given (e.g. because the parent is a
stateless widget) then to use SizedBox::shrink instead of the child that would
otherwise be included.
See also:
AnimatedSwitcher, which can fade from one child to the next as the subtree changes.AnimatedCrossFade, which can fade between two specific children.SliverVisibility, the sliver equivalent of this widget.
Fields§
§key: Option<KeyRef>See Widget::key.
child: WidgetRefThe widget to show or hide, as controlled by visible.
replacement: WidgetRefThe widget to use when the child is not visible, assuming that none
of the maintain flags (in particular, maintain_state) are
set.
The normal behavior is to replace the widget with a zero by zero box
(SizedBox::shrink).
See also:
AnimatedCrossFade, which can animate between two children.
visible: boolSwitches between showing the child or hiding it.
The maintain flags should be set to the same values regardless of the state of the
visible property, otherwise they will not operate correctly
(specifically, the state will be lost regardless of the state of
maintain_state whenever any of the maintain flags are
changed, since doing so will result in a subtree shape change).
Unless maintain_state is set, the child
subtree will be disposed (removed from the tree) while hidden.
maintain_state: boolWhether to maintain the State objects of the child subtree when it
is not visible.
Keeping the state of the subtree is potentially expensive (because it means all the
objects are still in memory; their resources are not released). It should only be
maintained if it cannot be recreated on demand. One example of when the state would be
maintained is if the child subtree contains a Navigator, since
that widget maintains elaborate state that cannot be recreated on the fly.
If this property is true, an Offstage widget is used to hide the child instead of
replacing it with replacement.
If this property is false, then maintain_animation must
also be false.
If this property is false, then maintain_focusability
must also be false.
Dynamically changing this value may cause the current state of the subtree to be lost
(and a new instance of the subtree, with new State objects, to be immediately created
if visible is true).
maintain_animation: boolWhether to maintain animations within the child subtree when it is not
visible.
To set this, maintain_state must also be set.
Keeping animations active when the widget is not visible is even more expensive than only maintaining the state.
One example when this might be useful is if the subtree is animating its layout in time
with an AnimationController, and the result of that layout is being used to influence
some other logic. If this flag is false, then any AnimationControllers hosted inside
the child subtree will be muted while the visible
flag is false.
If this property is true, no TickerMode widget is used.
If this property is false, then maintain_size must also be
false.
Dynamically changing this value may cause the current state of the subtree to be lost
(and a new instance of the subtree, with new State objects, to be immediately created
if visible is true).
maintain_size: boolWhether to maintain space for where the widget would have been.
To set this, maintain_animation and
maintain_state must also be set.
Maintaining the size when the widget is not visible is not notably
more expensive than just keeping animations running without maintaining the size, and
may in some circumstances be slightly cheaper if the subtree is simple and the
visible property is frequently toggled, since it avoids triggering a
layout change when the visible property is toggled. If the
child subtree is not trivial then it is significantly cheaper to not
even keep the state (see maintain_state).
If this property is false, Offstage is used.
If this property is false, then maintain_semantics and
maintain_interactivity must also be false.
Dynamically changing this value may cause the current state of the subtree to be lost
(and a new instance of the subtree, with new State objects, to be immediately created
if visible is true).
See also:
AnimatedOpacityandFadeTransition, which apply animations to the opacity for a more subtle effect.
maintain_semantics: boolWhether to maintain the semantics for the widget when it is hidden (e.g. for accessibility).
To set this, maintain_size must also be set.
By default, with maintain_semantics set to false, the
child is not visible to accessibility tools when it is hidden from the
user. If this flag is set to true, then accessibility tools will report the widget as
if it was present.
Nothing reads this flag while accessibility is deferred (see PORTING.md).
maintain_interactivity: boolWhether to allow the widget to be interactive when hidden.
To set this, maintain_size must also be set.
By default, with maintain_interactivity set to false,
touch events cannot reach the child when it is hidden from the user.
If this flag is set to true, then touch events will nonetheless be passed through.
maintain_focusability: boolWhether to allow the widget to receive focus when hidden. Only in effect if
visible is false.
To set this to true, maintain_state must also be set to true.
By default, with maintain_focusability set to false,
focus events cannot reach the child when this widget is not
visible because an ExcludeFocus widget is used to exclude the
child subtree from the focus tree. If this flag is set to true, then focus events will
reach the child subtree.
Implementations§
Source§impl Visibility
impl Visibility
Sourcepub fn new<K>(child: impl IntoWidget<K>) -> Visibility
pub fn new<K>(child: impl IntoWidget<K>) -> Visibility
Control whether the given child is visible; Dart’s
optional named arguments are the setters.
The maintain_semantics and
maintain_interactivity flags can only be set if
maintain_size is set.
The maintain_size flag can only be set if
maintain_animation is set.
The maintain_animation flag can only be set if
maintain_state is set.
Sourcepub fn maintain<K>(child: impl IntoWidget<K>) -> Visibility
pub fn maintain<K>(child: impl IntoWidget<K>) -> Visibility
Control whether the given child is visible.
This is equivalent to Visibility::new with all “maintain” fields set to true. This
constructor should be used in place of an Opacity widget that only
takes on values of 0.0 or 1.0, as it avoids extra compositing when fully opaque.
Sourcepub fn key(self, key: KeyRef) -> Visibility
pub fn key(self, key: KeyRef) -> Visibility
Dart Visibility(key:).
Sourcepub fn replacement<K>(self, replacement: impl IntoWidget<K>) -> Visibility
pub fn replacement<K>(self, replacement: impl IntoWidget<K>) -> Visibility
Dart Visibility(replacement:).
Sourcepub fn visible(self, visible: bool) -> Visibility
pub fn visible(self, visible: bool) -> Visibility
Dart Visibility(visible:).
Sourcepub fn maintain_state(self, maintain_state: bool) -> Visibility
pub fn maintain_state(self, maintain_state: bool) -> Visibility
Dart Visibility(maintainState:).
Sourcepub fn maintain_animation(self, maintain_animation: bool) -> Visibility
pub fn maintain_animation(self, maintain_animation: bool) -> Visibility
Dart Visibility(maintainAnimation:).
Sourcepub fn maintain_size(self, maintain_size: bool) -> Visibility
pub fn maintain_size(self, maintain_size: bool) -> Visibility
Dart Visibility(maintainSize:).
Sourcepub fn maintain_semantics(self, maintain_semantics: bool) -> Visibility
pub fn maintain_semantics(self, maintain_semantics: bool) -> Visibility
Dart Visibility(maintainSemantics:).
Sourcepub fn maintain_interactivity(self, maintain_interactivity: bool) -> Visibility
pub fn maintain_interactivity(self, maintain_interactivity: bool) -> Visibility
Dart Visibility(maintainInteractivity:).
Sourcepub fn maintain_focusability(self, maintain_focusability: bool) -> Visibility
pub fn maintain_focusability(self, maintain_focusability: bool) -> Visibility
Dart Visibility(maintainFocusability:).
Sourcepub fn of(app: &mut App, context: BuildContext) -> bool
pub fn of(app: &mut App, context: BuildContext) -> bool
Tells the visibility state of an element in the tree based off its ancestor
Visibility elements.
If there’s one or more Visibility widgets in the ancestor tree, this will return
true if and only if all of those widgets have visible set to true.
If there is no Visibility widget in the ancestor tree of the specified build
context, this will return true.
This will register a dependency from the specified context on any Visibility
elements in the ancestor tree, such that if any of their visibilities changes, the
specified context will be rebuilt.
Trait Implementations§
Source§impl Debug for Visibility
impl Debug for Visibility
Source§impl StatelessWidget for Visibility
impl StatelessWidget for Visibility
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn debug_check_constructor(&self)
fn debug_check_constructor(&self)
Source§fn build(&self, _app: &mut App, _context: BuildContext) -> WidgetRef
fn build(&self, _app: &mut App, _context: BuildContext) -> WidgetRef
Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
this is PreferredSizeWidget: a widget that implements PreferredSizeWidget
answers with itself, which is what a parent asking an erased child for its preferred
size reads.Auto Trait Implementations§
impl !RefUnwindSafe for Visibility
impl !Send for Visibility
impl !Sync for Visibility
impl !UnwindSafe for Visibility
impl Forget for Visibility
impl Freeze for Visibility
impl Move for Visibility
impl Unpin for Visibility
impl UnsafeUnpin for Visibilitywhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
impl<W> IntoWidget<StatelessKind> for Wwhere
W: StatelessWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.