widthOf static method

double widthOf(
  1. BuildContext context,
  2. String text,
  3. TextStyle style
)

The width EmojiText lays text out at on one line under style.

Implementation

static double widthOf(BuildContext context, String text, TextStyle style) {
  final painter = TextPainter(
    text: TextSpan(
      style: MediaQuery.boldTextOf(context)
          ? style.merge(const TextStyle(fontWeight: FontWeight.bold))
          : style,
      children: [_spanOf(text, null, EmojiFont.of(context))],
    ),
    textDirection: Directionality.of(context),
    textScaler: MediaQuery.textScalerOf(context),
    locale: Localizations.maybeLocaleOf(context),
    maxLines: 1,
  )..layout();
  try {
    return painter.maxIntrinsicWidth;
  } finally {
    painter.dispose();
  }
}