BidiText class
A text widget that automatically detects and sets text direction based on content.
BidiText is a StatelessWidget that wraps Flutter's standard Text widget
and automatically determines whether the text should be displayed in
right-to-left (RTL) or left-to-right (LTR) direction based on its content.
Use the primary constructor for plain strings and BidiText.rich for styled InlineSpan trees (mirrors Text.rich).
Breaking change (v2.0.0)
BidiText no longer extends Text. It extends StatelessWidget and builds
a Text internally. If your code relied on bidiTextInstance is Text type
checks, update them — all widget behaviour is identical.
Example:
BidiText('Hello world!') // Will display in LTR direction
BidiText('مرحبا بالعالم!') // Will display in RTL direction
BidiText('Hello مرحبا') // Direction will be determined by content analysis
// Styled text (mirrors Text.rich):
BidiText.rich(
TextSpan(children: [
TextSpan(text: 'Hello ', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: 'مرحبا'),
]),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- BidiText
Constructors
- BidiText(String data, {Key? key, TextStyle? style, StrutStyle? strutStyle, TextAlign? textAlign, Locale? locale, bool? softWrap, TextOverflow? overflow, TextScaler? textScaler, int? maxLines, String? semanticsLabel, TextWidthBasis? textWidthBasis, TextHeightBehavior? textHeightBehavior, Color? selectionColor, int? sampleLength = 50})
-
Creates a BidiText widget with a plain string.
const
- BidiText.rich(InlineSpan textSpan, {Key? key, TextStyle? style, StrutStyle? strutStyle, TextAlign? textAlign, Locale? locale, bool? softWrap, TextOverflow? overflow, TextScaler? textScaler, int? maxLines, String? semanticsLabel, TextWidthBasis? textWidthBasis, TextHeightBehavior? textHeightBehavior, Color? selectionColor, int? sampleLength = 50})
-
Creates a BidiText widget with an InlineSpan — a drop-in replacement
for Text.rich.
const
Properties
- data → String?
-
The plain text string. Non-null only when using the primary constructor.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- locale → Locale?
-
Used to select a font when the same Unicode character can be rendered
differently depending on the locale.
final
- maxLines → int?
-
Maximum number of lines to show.
final
- overflow → TextOverflow?
-
How visual overflow should be handled.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sampleLength → int?
-
Maximum number of characters to sample for direction detection.
final
- selectionColor → Color?
-
The color to use when painting the selection.
final
- semanticsLabel → String?
-
An optional semantics label for this widget.
final
- softWrap → bool?
-
Whether the text should break at soft line breaks.
final
- strutStyle → StrutStyle?
-
The strut style used for the vertical layout.
final
- style → TextStyle?
-
The text style to apply. Defaults to ambient DefaultTextStyle.
final
- textAlign → TextAlign?
-
How the text should be aligned horizontally.
final
- textDirection → TextDirection?
-
no setter
- textHeightBehavior → TextHeightBehavior?
-
final
- textScaler → TextScaler?
-
The font scaling strategy to use when laying out and rendering the text.
final
- textSpan → InlineSpan?
-
The InlineSpan for rich text. Non-null only when using BidiText.rich.
final
- textWidthBasis → TextWidthBasis?
-
Defines how to measure the width of the rendered text.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited