2024-01-13 17:20:58 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:lightmeter/res/dimens.dart';
|
|
|
|
|
|
|
|
double dialogTextHeight(
|
|
|
|
BuildContext context,
|
|
|
|
String text,
|
|
|
|
TextStyle? style,
|
|
|
|
double textPadding,
|
|
|
|
) =>
|
|
|
|
textHeight(
|
|
|
|
text,
|
|
|
|
style,
|
|
|
|
MediaQuery.sizeOf(context).width - Dimens.dialogMargin.horizontal - textPadding,
|
|
|
|
);
|
|
|
|
|
|
|
|
double textHeight(
|
|
|
|
String text,
|
|
|
|
TextStyle? style,
|
|
|
|
double maxWidth,
|
2024-07-23 21:19:41 +00:00
|
|
|
) =>
|
|
|
|
textSize(text, style, maxWidth).height;
|
|
|
|
|
|
|
|
Size textSize(
|
|
|
|
String text,
|
|
|
|
TextStyle? style,
|
|
|
|
double maxWidth,
|
2024-01-13 17:20:58 +00:00
|
|
|
) {
|
|
|
|
final TextPainter titlePainter = TextPainter(
|
|
|
|
text: TextSpan(
|
|
|
|
text: text,
|
|
|
|
style: style,
|
|
|
|
),
|
|
|
|
textDirection: TextDirection.ltr,
|
|
|
|
)..layout(maxWidth: maxWidth);
|
2024-07-23 21:19:41 +00:00
|
|
|
return titlePainter.size;
|
2024-01-13 17:20:58 +00:00
|
|
|
}
|
2024-10-24 10:09:11 +00:00
|
|
|
|
|
|
|
extension TextLineHeight on TextStyle {
|
|
|
|
double get lineHeight => fontSize! * height!;
|
|
|
|
}
|