fluent2FitScale function

double fluent2FitScale(
  1. BuildContext context,
  2. Iterable<String> lines,
  3. TextStyle style,
  4. double room, {
  5. double least = 0,
})

The text scale at which each of lines in style stands whole on one line in room: the reader's own (at style's size, from context) where they fit, else the largest that fits, never under least. A navigation label is never cut: where its place cannot grow (the phone tab bar) it is drawn at this scale, as iOS keeps a tab bar's words at their size while the reader's text grows.

Implementation

double fluent2FitScale(
  BuildContext context,
  Iterable<String> lines,
  TextStyle style,
  double room, {
  double least = 0,
}) {
  style = _drawn(context, style);
  final size = style.fontSize ?? 14;
  final reader = MediaQuery.textScalerOf(context).scale(size) / size;
  final widest = _widest(lines, style);
  if (widest <= 0 || !room.isFinite || room <= 0) return reader;
  final fits = room / widest;
  final floor = least < reader ? least : reader;
  return fits >= reader ? reader : (fits < floor ? floor : fits);
}