import 'dart:math'; import 'package:flutter/material.dart'; import 'package:auto_size_text/auto_size_text.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: AutoSizeText( value, style: TextStyle(fontSize: 40), ), // 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 = " ", context}) { const double result = 40.0; try { double width = MediaQuery.of(context).size.width; double height = MediaQuery.of(context).size.height; double global = width * height / 2; double scale = (global / value.length); final pixelOfLetter = sqrt(scale); final pixelOfLetterP = pixelOfLetter - (pixelOfLetter * 7) / 100; if (pixelOfLetterP > result) { return result; } return pixelOfLetterP; } catch (e) { return result; } } }