Text Widget

Source Code​

				
					Text(
  'Welcome to Flutter!',
  style: TextStyle(
    fontSize: 20,
    fontWeight: FontWeight.bold,
    color: Colors.blue,
  ),
  textAlign: TextAlign.center,
  maxLines: 2,
  overflow: TextOverflow.ellipsis,
)

				
			

Ai Code Analizer

🎨 2. Default Behavior

Without any additional parameters:

  • Font: Uses the app’s default font (typically Roboto on Android).

  • Size: Inherits the font size from the app’s theme (usually 14.0 or 16.0 sp).

  • Color: Also inherited from the current ThemeData.

  • Alignment: If not wrapped in a layout widget, it takes as much space as the text needs.

  • Overflow: No handling unless explicitly set (overflow property).

  • Soft wrap: Enabled by default (softWrap: true).


⚙️ 3. Important Properties You Can Use

You can customize the Text widget with many parameters. Here are key ones:

PropertyDescription
styleA TextStyle object to define font size, weight, color, etc.
textAlignAligns the text within its container (left, center, right, etc.).
overflowHandles overflow (ellipsis, fade, clip, etc.).
maxLinesLimits the number of lines the text can occupy.
softWrapWhether the text should break at soft line breaks.
textDirectionDetermines left-to-right or right-to-left layout.
localeUsed to select region-specific glyphs.
semanticsLabelA label used by accessibility tools like screen readers.