import 'dart:math'; import 'package:flutter/material.dart'; class NumberDisplay extends StatelessWidget { NumberDisplay({this.value: ''}); final String value; GlobalKey stickyKey = GlobalKey(); @override Widget build(BuildContext context) { return Expanded( child: Padding( padding: const EdgeInsets.only(left: 20.0, right: 20.0, top: 20.0 ), child: Container( key: stickyKey, alignment: Alignment.topLeft, child: AnimatedDefaultTextStyle( duration: const Duration(milliseconds: 200), style: TextStyle( fontSize: fontSizeCalc(value: value), fontWeight: FontWeight.bold, color: Colors.black, ), child: Text( value, ), ), )), ); } double fontSizeCalc({ String value = " " }) { const double result = 40.0; try { const double global = 100000.0; double scale = (global / value.length); final pixelOfLetter = sqrt(scale); final pixelOfLetterP = pixelOfLetter - (pixelOfLetter * 5) / 100; if(pixelOfLetterP> result){ return result; } return pixelOfLetterP; } catch(e) { return result; } } }