setText method
Creates a customizable text widget with font styling options.
This method provides fine-grained control over text appearance including font family, color, size, alignment, and overflow behavior. Supports both single-line and multi-line text.
Parameters:
name: The text content to display.txtFontFamily: The font family to apply.txtColor: The text color.txtSize: The font size.isCenter: Whether to center-align the text (defaults to false).isMultiLine: If true, text wraps naturally; if false, applies ellipsis overflow (defaults to false).maxLine: Maximum number of lines whenisMultiLineis false (defaults to 1).
Returns a styled Text widget with the specified formatting.
Example:
setText(
'Welcome User',
'Roboto',
Colors.black87,
16.0,
isCenter: true,
maxLine: 2,
);
Implementation
Widget setText(
String name, String txtFontFamily, Color txtColor, double txtSize,
{bool? isCenter = false, bool isMultiLine = false, int maxLine = 1}) {
return isMultiLine
? Text(
name,
textAlign: isCenter == true ? TextAlign.center : TextAlign.start,
style: TextStyle(
fontFamily: txtFontFamily, color: txtColor, fontSize: txtSize),
)
: Text(
name,
overflow: TextOverflow.ellipsis,
maxLines: maxLine,
textAlign: isCenter == true ? TextAlign.center : TextAlign.start,
style: TextStyle(
fontFamily: txtFontFamily, color: txtColor, fontSize: txtSize),
);
}