# Text Class in flutter
###### tags: `flutter_widget`
> [Whole Note Link](https://hackmd.io/6MJMhshwRfaHUTnXmjHjaA)
> [Official API Website of **Text** Widget](https://api.flutter.dev/flutter/widgets/Text-class.html)
## Constructors
### 1. [Basic](https://api.flutter.dev/flutter/widgets/Text/Text.html) : create a text widget
``` java
Text(
String data,
{
Key key,
TextStyle style,
StrutStyle strutStyle,
TextAlign textAlign,
TextDirection textDirection,
Locale locale,
bool softWrap,
TextOverflow overflow,
double textScaleFactor,
int maxLines,
String semanticsLabel,
TextWidthBasis textWidthBasis
}
)
```
### 2. [Rich](https://api.flutter.dev/flutter/widgets/Text/Text.rich.html) : create text widget with InlineSpan
``` java
Text.rich(
InlineSpan textSpan,
{
Key key,
TextStyle style,
StrutStyle strutStyle,
TextAlign textAlign,
TextDirection textDirection,
Locale locale,
bool softWrap,
TextOverflow overflow, double textScaleFactor,
int maxLines,
String semanticsLabel,
TextWidthBasis textWidthBasis
}
)
```
## Properties
### **String data** :
- The texts to display
- Will be null if a textSpan provided instead
### **Locale locale** :
- Select a front when same Unicode character can be rendered differently
- By default its value is inherited from enclosing app with **Localizations.localeOf(context)**
### **int maxLines** :
- Optional maximum number of lines for text to span
- If text exceeds given maxLines, it will be truncated according to **overflow** rule
- If it's null, **DefaultTextStyle** will take precedence
### **TextOverflow overflow** :
- How visual overflow should be handled
- Constants : ( Usage: TextOverflow.xxxx )
- **clip** : clip overflowing text
- **ellipsis** : use ellipsis to show overflow
- **fade** : fade overflow text
- **visible** : render overflowing text outside of its container
- **values** : return the enum list
- clip = TextOverflow(0)
- fade = TextOverflow(1)
- ellipsis = TextOverflow(2)
- visible = TextOverflow(3)
### **String semanticsLabel** :
- An alternative semantics label for the text
- E.g. **$$** means **double dollars**
``` java
Text(r'$$', semanticsLabel: 'Double dollars')
```
- Useful for replacing abbreviations and shorthands
### **bool softWrap**
- Whether text should be break at soft line break
- If false, the glyphs in the text will be positioned as if there was unlimited horizontal space
### **StructStyle strutStyle** :
- Text and line arrangement
- Strut style defines the strut, which sets minimum vertical layout metrics (minimum height a line can be relative to the baseline)
### **TextStyle style** :
- The style used for texts
- Properties :
- **Paint background**
- **Color backgroundColor**
- **Color color**
- **String debugLabel**
- **TextDecoration decoration**
- **Color decorationColor**
- **TextDecorationStyle decorationStyle**
- **double decorationThickness**
- **String fontFamily**
- **List<String> fontFamilyFallback**
- **Paint foreground**
- **int hashCode**
- **double height**
- **bool inherit**
- **double letterSpacing**
- **Locale locale**
- **List<Shadow> shadows**
- **TextBaseline textBaseline**
- **double wordSpacing**
### **TextAlign textAlign** :
- How text should be aligned
- Constants :
- **center**
- **end** : align text on the trailing edge of container
- **justify**
- soft line break : fill the width of the container
- hard line break : aligned towards the start edge
- **left**
- **right**
- **start** : align text on the leading edge of container
- **values**
- left: TextAlign(0)
- right : TextAlign(1)
- center : TextAlign(2)
- justify : TextAlign(3)
- start : TextAlign(4)
- end : TextAlign(5)
### **TextDirection textDirection** :
- Directionality of text
- Constants :
- **ltr** : text flows from left to right
- **rtl** : text flows from right to left
- **values**
- ltr : TextDirection(1)
- rtl : TextDirection(0)
### **double textScaleFactor**
- Number of pixels for each logical pixel
- E.g. textScaleFactor=1.5, text will be 50% larger than origin font size
### **InlineSpan textSpan**
- Display as InlineSpan
### **TextWidthBasis textWidthBasis**
- How to measure the width of rendered text
- Constants :
- **longestLine** : width will be exactly enough to contain the longest line
- **parent**
- multiline text : take up full width given by parent
- single line text : take up minimum amount of width
- **values**
- parent : TextWidthBasis(0)
- longest : TextWidthBasis(1)
## Method
### build(BuildContext context) -> Widget
- Describes the part of the user interface represented by this widget
### debugFillProperties(DiagnosticPropertiesBuilder properties) -> void
- Add additional properties associated with the node