encodeTextStyle function
Encodes a TextStyle into a map suitable for platform view method channel calls.
Returns null if style is null (signals "clear style" on the native side).
Keys: fontSize (double), fontWeight (CSS 100-900 int), italic (bool),
fontFamily (string). Only non-null fields are included.
Color is intentionally excluded — use dedicated tint/labelColor/iconColor params.
Implementation
Map<String, dynamic>? encodeTextStyle(TextStyle? style, BuildContext context) {
if (style == null) return null;
final map = <String, dynamic>{};
if (style.fontSize != null) map['fontSize'] = style.fontSize;
if (style.fontWeight != null) {
// FontWeight.index is 0-based (w100=0 … w900=8); CSS scale is 100-900.
map['fontWeight'] = (style.fontWeight!.index + 1) * 100;
}
if (style.fontStyle == FontStyle.italic) map['italic'] = true;
if (style.fontFamily != null) map['fontFamily'] = style.fontFamily;
return map;
}