TextComponent.translate constructor

TextComponent.translate(
  1. String key, {
  2. List? conversionFlags,
  3. Color? color,
  4. bool? bold,
  5. bool? italic,
  6. bool? underlined,
  7. bool? strikethrough,
  8. bool? obfuscated,
  9. TextClickEvent? clickEvent,
  10. TextHoverEvent? hoverEvent,
  11. String? insertion,
  12. String? fallback,
})

Implementation

TextComponent.translate(
  String key, {
  /// a List containing a String, TextComponent or another List of TextComponents that replace placeholder values(e.g $s)
  List<dynamic>? conversionFlags,
  this.color,
  this.bold,
  this.italic,
  this.underlined,
  this.strikethrough,
  this.obfuscated,
  this.clickEvent,
  this.hoverEvent,
  this.insertion,
  String? fallback,
}) {
  value = {'translate': key};
  if (fallback != null) value['fallback'] = fallback;
  if (conversionFlags != null && conversionFlags.isNotEmpty) {
    value['with'] = [];
    for (var c in conversionFlags) {
      if (c is List<TextComponent>) {
        value['with'].add(c.map((TextComponent x) => x.toMap()).toList());
      }
      if (c is TextComponent) value['with'].add(c.toMap());
      if (c is String) value['with'].add(TextComponent(c).toMap());
    }
  }
}