Dart API ReferenceintlTextDirection

TextDirection class

Bidi stands for Bi-directional text. According to http://en.wikipedia.org/wiki/Bi-directional_text: Bi-directional text is text containing text in both text directionalities, both right-to-left (RTL) and left-to-right (LTR). It generally involves text containing different types of alphabets, but may also refer to boustrophedon, which is changing text directionality in each row.

This file provides some utility classes for determining directionality of text, switching CSS layout from LTR to RTL, and other normalizing utilities needed when switching between RTL and LTR formatting.

It defines the TextDirection class which is used to represent directionality of text, In most cases, it is preferable to use bidiformatter.dart, which provides bidi functionality in the given directional context, instead of using bidiutils.dart directly.

class TextDirection {
  static const LTR = const TextDirection._('LTR', 'ltr');
  static const RTL = const TextDirection._('RTL', 'rtl');
  // If the directionality of the text cannot be determined and we are not using
  // the context direction (or if the context direction is unknown), then the
  // text falls back on the more common ltr direction.
  static const UNKNOWN = const TextDirection._('UNKNOWN', 'ltr');

  /**
   * Textual representation of the directionality constant. One of
   * 'LTR', 'RTL', or 'UNKNOWN'.
   */
  final String value;

  /** Textual representation of the directionality when used in span tag. */
  final String spanText;

  const TextDirection._(this.value, this.spanText);

  /**
   * Returns true if [otherDirection] is known to be different from this
   * direction.
   */
  bool isDirectionChange(TextDirection otherDirection) {
    return otherDirection != TextDirection.UNKNOWN && this != otherDirection;
  }
}

Static Properties

const LTR #

static const LTR = const TextDirection._('LTR', 'ltr');

const RTL #

static const RTL = const TextDirection._('RTL', 'rtl');

const UNKNOWN #

static const UNKNOWN = const TextDirection._('UNKNOWN', 'ltr');

Properties

final String spanText #

Textual representation of the directionality when used in span tag.

final String spanText;

final String value #

Textual representation of the directionality constant. One of 'LTR', 'RTL', or 'UNKNOWN'.

final String value;

Methods

bool isDirectionChange(TextDirection otherDirection) #

Returns true if otherDirection is known to be different from this direction.

bool isDirectionChange(TextDirection otherDirection) {
  return otherDirection != TextDirection.UNKNOWN && this != otherDirection;
}