tr method
Creates a Text widget with a localized string obtained from the given context.
This method enhances the Text widget by allowing for the easy integration of localized strings. It automatically fetches the translated string using the key provided in the data property of the Text widget.
Parameters:
- context: The BuildContext to access the localization provider.
- style: An optional TextStyle to apply to the Text widget. Inherits the style from the original Text widget if not specified.
- textAlign: An optional TextAlign to define how the text is aligned. Inherits the alignment from the original Text widget if not specified.
- overflow: How visual overflow should be handled. Inherits the overflow setting from the original Text widget if not specified.
Returns: A Text widget displaying the localized string.
Implementation
Text tr([BuildContext? context]) {
return Text(
data!.tr(
context), // `data` is assumed to be a String (the text content of this widget).
style: style,
textAlign: textAlign,
overflow: overflow,
);
}