import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class Util { Color stringToColor(String str) { if (str == null || str.length == 0 || str.length != 9) { return Colors.white; } String strColor = str.substring(1, 9); int value = int.parse(strColor, radix: 16); return Color(value); } void setPageTitle(String title){ SystemChrome.setApplicationSwitcherDescription(ApplicationSwitcherDescription(label: title)); } Size boundingTextSize(String text,TextStyle style,double maxWidth,{int maxLines = 100}){ TextPainter textPainter = TextPainter( textDirection: TextDirection.ltr, text: TextSpan(text: text,style: style), maxLines: maxLines )..layout(maxWidth: maxWidth); return textPainter.size; } bool didExceedMaxLines(String text,TextStyle style,double width,int maxLines){ TextPainter _textPainter = TextPainter( maxLines: maxLines, text: TextSpan( text: text, style: style), textDirection: TextDirection.ltr)..layout( maxWidth: width ); if (_textPainter.didExceedMaxLines){ return true; } return false; } }