customFont method

TextStyle customFont({
  1. required Map customizacao,
})

Creates a custom TextStyle based on the customization configuration.

Reads the following properties from customization:

  • 'font_size': Text size (scaled by 1.5x)
  • 'font_style': Object with 'bold' and 'italic' booleans
  • 'font_name': Optional custom font family name

Returns a configured TextStyle object.

Implementation

TextStyle customFont({required Map customizacao}) {
  FontWeight weight = FontWeight.normal;
  FontStyle style = FontStyle.normal;
  double fontSize =
      (int.tryParse(customizacao['font_size'].toString()) ?? 12).toDouble();
  fontSize *= 1.5;
  if (customizacao.containsKey('font_style')) {
    if (customizacao['font_style'].containsKey('bold')) {
      weight = switch (customizacao['font_style']['bold'] ?? false) {
        true => FontWeight.bold,
        false => FontWeight.normal,
        _ => FontWeight.normal,
      };
    } else {
      weight = FontWeight.normal;
    }

    if (customizacao['font_style'].containsKey('italic')) {
      style = switch (customizacao['font_style']['italic'] ?? false) {
        true => FontStyle.italic,
        false => FontStyle.normal,
        _ => FontStyle.normal,
      };
    } else {
      style = FontStyle.normal;
    }
  }
  String? fontName;
  if (customizacao.containsKey('font_name')) {
    fontName = customizacao['font_name'];
  }

  return TextStyle(
      fontSize: fontSize.toDouble(),
      fontWeight: weight,
      fontStyle: style,
      fontFamily: fontName);
}