Skip to main content

DefaultTextStyle

Struct DefaultTextStyle 

Source
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 provided Animation to 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>§style: TextStyle

The text style to apply.

§text_align: Option<TextAlign>

How each line of text in the Text widget should be aligned horizontally.

§soft_wrap: bool

Whether 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: TextOverflow

How 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: TextWidthBasis

The 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: WidgetRef

The widget below this widget in the tree.

Implementations§

Source§

impl DefaultTextStyle

Source

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.

Source

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.

Source

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.

Source

pub fn key(self, key: KeyRef) -> DefaultTextStyle

Dart DefaultTextStyle(key:).

Source

pub fn text_align(self, text_align: TextAlign) -> DefaultTextStyle

Dart DefaultTextStyle(textAlign:).

Source

pub fn soft_wrap(self, soft_wrap: bool) -> DefaultTextStyle

Dart DefaultTextStyle(softWrap:).

Source

pub fn overflow(self, overflow: TextOverflow) -> DefaultTextStyle

Dart DefaultTextStyle(overflow:).

Source

pub fn max_lines(self, max_lines: i32) -> DefaultTextStyle

Dart DefaultTextStyle(maxLines:). Must be greater than zero.

Source

pub fn text_width_basis( self, text_width_basis: TextWidthBasis, ) -> DefaultTextStyle

Dart DefaultTextStyle(textWidthBasis:).

Source

pub fn text_height_behavior( self, text_height_behavior: TextHeightBehavior, ) -> DefaultTextStyle

Dart DefaultTextStyle(textHeightBehavior:).

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DefaultTextStyle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl InheritedTheme for DefaultTextStyle

Source§

fn wrap( &self, _app: &mut App, _context: BuildContext, child: WidgetRef, ) -> WidgetRef

Return a copy of this inherited theme with the specified child. Read more
Source§

impl InheritedWidget for DefaultTextStyle

Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s 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 child(&self) -> &WidgetRef

The widget below this widget in the tree.
Source§

fn update_should_notify(&self, old_widget: &DefaultTextStyle) -> bool

Whether the framework should notify widgets that inherit from this widget. Read more
Source§

fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme>

Dart’s this is InheritedTheme: an inherited widget that is an InheritedTheme answers with itself, which is what InheritedTheme::capture collects.
Source§

fn debug_check_constructor(&self)

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 DefaultTextStyle
where *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
where Rc<dyn Key>: Unpin, &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin, *const u8 is !null: Unpin, Rc<Paint>: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for DefaultTextStyle

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<InheritedKind> for W
where W: InheritedWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>