pub struct DefaultTextStyle {
pub key: Option<KeyRef>,
pub style: TextStyle,
pub text_align: Option<TextAlign>,
pub soft_wrap: bool,
pub overflow: TextOverflow,
pub max_lines: Option<i32>,
pub text_width_basis: TextWidthBasis,
pub text_height_behavior: Option<TextHeightBehavior>,
pub child: WidgetRef,
}Expand description
The text style to apply to descendant Text widgets which don’t have an explicit style.
A MediaQuery ancestor of a Text widget may still override the TextStyle.height,
TextStyle.letterSpacing, and TextStyle.wordSpacing of the TextStyle set by this
DefaultTextStyle widget through its MediaQueryData.lineHeightScaleFactorOverride,
MediaQueryData.letterSpacingOverride, and MediaQueryData.wordSpacingOverride members.
See also:
AnimatedDefaultTextStyle, which animates changes in the text style smoothly over a given duration.DefaultTextStyleTransition, which takes a providedAnimationto animate changes in text style smoothly over time.
Dart’s named constructor arguments are the fluent setters
(DefaultTextStyle::new(style, child).max_lines(2)).
Fields§
§key: Option<KeyRef>See InheritedWidget::key.
style: TextStyleThe text style to apply.
text_align: Option<TextAlign>How each line of text in the Text widget should be aligned horizontally.
soft_wrap: boolWhether the text should break at soft line breaks.
If false, the glyphs in the text will be positioned as if there was unlimited horizontal space.
This also decides the overflow property’s behavior. If this is true or null, the
glyph causing overflow, and those that follow, will not be rendered.
overflow: TextOverflowHow visual overflow should be handled.
If soft_wrap is true or null, the glyph causing overflow, and those that follow,
will not be rendered. Otherwise, it will be shown with the given overflow option.
max_lines: Option<i32>An optional maximum number of lines for the text to span, wrapping if necessary. If
the text exceeds the given number of lines, it will be truncated according to
overflow.
If this is 1, text will not wrap. Otherwise, text will be wrapped at the edge of the box.
If this is non-null, it will override even explicit null values of Text.max_lines.
text_width_basis: TextWidthBasisThe strategy to use when calculating the width of the Text.
See TextWidthBasis for possible values and their implications.
text_height_behavior: Option<TextHeightBehavior>Defines how to apply TextStyle.height over and under text.
child: WidgetRefThe widget below this widget in the tree.
Implementations§
Source§impl DefaultTextStyle
impl DefaultTextStyle
Sourcepub fn new<K>(style: TextStyle, child: impl IntoWidget<K>) -> DefaultTextStyle
pub fn new<K>(style: TextStyle, child: impl IntoWidget<K>) -> DefaultTextStyle
Creates a default text style for the given subtree.
Consider using DefaultTextStyle.merge to inherit styling information from the
current default text style for a given BuildContext.
The max_lines property may be None (and indeed defaults to None), but if it is
not None, it must be greater than zero.
Sourcepub fn fallback() -> DefaultTextStyle
pub fn fallback() -> DefaultTextStyle
A default text style that provides fallback values.
Returned from of when the given BuildContext doesn’t have an
enclosing default text style.
This constructor creates a DefaultTextStyle with an invalid child, which means
the constructed value cannot be incorporated into the tree.
Sourcepub fn merge<K>(child: impl IntoWidget<K>) -> DefaultTextStyleMerge
pub fn merge<K>(child: impl IntoWidget<K>) -> DefaultTextStyleMerge
Creates a default text style that overrides the text styles in scope at this point in the widget tree.
The given style is merged with the style from the default text style for the
BuildContext where the widget is inserted, and any of the other arguments that are
not None replace the corresponding properties on that same default text style.
This constructor cannot be used to override the max_lines property of the ancestor
with the value None, since None here is used to mean “defer to ancestor”. To
replace a non-None max_lines from an ancestor with the None value (to remove the
restriction on number of lines), manually obtain the ambient DefaultTextStyle
using of, then create a new DefaultTextStyle using
new directly.
If a text_height_behavior is provided, the existing configuration will be replaced
completely. To retain part of the original text_height_behavior, manually obtain the
ambient DefaultTextStyle using of.
Dart’s optional named arguments are the setters of the DefaultTextStyleMerge this
returns.
Sourcepub fn key(self, key: KeyRef) -> DefaultTextStyle
pub fn key(self, key: KeyRef) -> DefaultTextStyle
Dart DefaultTextStyle(key:).
Sourcepub fn text_align(self, text_align: TextAlign) -> DefaultTextStyle
pub fn text_align(self, text_align: TextAlign) -> DefaultTextStyle
Dart DefaultTextStyle(textAlign:).
Sourcepub fn soft_wrap(self, soft_wrap: bool) -> DefaultTextStyle
pub fn soft_wrap(self, soft_wrap: bool) -> DefaultTextStyle
Dart DefaultTextStyle(softWrap:).
Sourcepub fn overflow(self, overflow: TextOverflow) -> DefaultTextStyle
pub fn overflow(self, overflow: TextOverflow) -> DefaultTextStyle
Dart DefaultTextStyle(overflow:).
Sourcepub fn max_lines(self, max_lines: i32) -> DefaultTextStyle
pub fn max_lines(self, max_lines: i32) -> DefaultTextStyle
Dart DefaultTextStyle(maxLines:). Must be greater than zero.
Sourcepub fn text_width_basis(
self,
text_width_basis: TextWidthBasis,
) -> DefaultTextStyle
pub fn text_width_basis( self, text_width_basis: TextWidthBasis, ) -> DefaultTextStyle
Dart DefaultTextStyle(textWidthBasis:).
Sourcepub fn text_height_behavior(
self,
text_height_behavior: TextHeightBehavior,
) -> DefaultTextStyle
pub fn text_height_behavior( self, text_height_behavior: TextHeightBehavior, ) -> DefaultTextStyle
Dart DefaultTextStyle(textHeightBehavior:).
Sourcepub fn of(app: &mut App, context: BuildContext) -> DefaultTextStyle
pub fn of(app: &mut App, context: BuildContext) -> DefaultTextStyle
The closest instance of this class that encloses the given context.
If no such instance exists, returns an instance created by
fallback, which contains fallback values.
Typical usage is as follows:
let style = DefaultTextStyle::of(app, context);Trait Implementations§
Source§impl Clone for DefaultTextStyle
impl Clone for DefaultTextStyle
Source§impl Debug for DefaultTextStyle
impl Debug for DefaultTextStyle
Source§impl InheritedTheme for DefaultTextStyle
impl InheritedTheme for DefaultTextStyle
Source§impl InheritedWidget for DefaultTextStyle
impl InheritedWidget for DefaultTextStyle
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 update_should_notify(&self, old_widget: &DefaultTextStyle) -> bool
fn update_should_notify(&self, old_widget: &DefaultTextStyle) -> bool
Source§fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme>
fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme>
this is InheritedTheme: an inherited widget that is an InheritedTheme
answers with itself, which is what InheritedTheme::capture collects.Auto Trait Implementations§
impl !RefUnwindSafe for DefaultTextStyle
impl !Send for DefaultTextStyle
impl !Sync for DefaultTextStyle
impl !UnwindSafe for DefaultTextStyle
impl Forget for DefaultTextStyle
impl Freeze for DefaultTextStylewhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
&'static dyn ColorExtension: Freeze,
*const RcInner<dyn ColorExtension> is !null: Freeze,
PhantomData<RcInner<dyn ColorExtension>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<String>: Freeze,
*const RcInner<Paint> is !null: Freeze,
PhantomData<RcInner<Paint>>: Freeze,
PhantomData<Shadow>: Freeze,
PhantomData<FontFeature>: Freeze,
PhantomData<FontVariation>: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for DefaultTextStyle
impl Unpin for DefaultTextStyle
impl UnsafeUnpin for DefaultTextStylewhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
&'static dyn ColorExtension: UnsafeUnpin,
*const RcInner<dyn ColorExtension> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
*const RcInner<Paint> is !null: UnsafeUnpin,
PhantomData<RcInner<Paint>>: UnsafeUnpin,
PhantomData<Shadow>: UnsafeUnpin,
PhantomData<FontFeature>: UnsafeUnpin,
PhantomData<FontVariation>: 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<W> IntoWidget<InheritedKind> for Wwhere
W: InheritedWidget,
impl<W> IntoWidget<InheritedKind> for Wwhere
W: InheritedWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.