m3_lightmeter/lib/utils/text_height.dart

30 lines
626 B
Dart
Raw Normal View History

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,
) {
final TextPainter titlePainter = TextPainter(
text: TextSpan(
text: text,
style: style,
),
textDirection: TextDirection.ltr,
)..layout(maxWidth: maxWidth);
return titlePainter.height;
}