TranslatableText function

Text TranslatableText({
  1. required Language displayLanguage,
  2. required List<TranslateOption> options,
  3. TextStyle? style,
  4. StrutStyle? strutStyle,
  5. TextAlign? textAlign,
  6. TextDirection? textDirection,
  7. Locale? locale,
  8. bool? softWrap,
  9. TextOverflow? overflow,
  10. double? textScaleFactor,
  11. int? maxLines,
  12. String? semanticsLabel,
  13. TextWidthBasis? textWidthBasis,
  14. TextHeightBehavior? textHeightBehavior,
})

Implementation

Text TranslatableText({
  required Language displayLanguage,
  required List<TranslateOption> options,
  TextStyle? style,
  StrutStyle? strutStyle,
  TextAlign?  textAlign,
  TextDirection? textDirection,
  Locale? locale,
  bool? softWrap,
  TextOverflow? overflow,
  double? textScaleFactor,
  int? maxLines,
  String? semanticsLabel,
  TextWidthBasis? textWidthBasis,
  TextHeightBehavior? textHeightBehavior,
}){
  int index = options.indexWhere((option) => option.language.languageName == displayLanguage.languageName);
  //If the selected language is not found
  String displayText = index == -1 ? 'Language not Supported': options[index].text;
  return Text(
    displayText,
    locale: locale,
    maxLines: maxLines,
    overflow: overflow,
    semanticsLabel: semanticsLabel,
    softWrap: softWrap,
    strutStyle: strutStyle,
    style: style,
    textAlign: textAlign,
    textDirection: textDirection,
    textHeightBehavior: textHeightBehavior,
    textScaleFactor: textScaleFactor,
    textWidthBasis: textWidthBasis,
  );
}