mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-25 17:00:39 +00:00
40 lines
834 B
Dart
40 lines
834 B
Dart
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,
|
|
) =>
|
|
textSize(text, style, maxWidth).height;
|
|
|
|
Size textSize(
|
|
String text,
|
|
TextStyle? style,
|
|
double maxWidth,
|
|
) {
|
|
final TextPainter titlePainter = TextPainter(
|
|
text: TextSpan(
|
|
text: text,
|
|
style: style,
|
|
),
|
|
textDirection: TextDirection.ltr,
|
|
)..layout(maxWidth: maxWidth);
|
|
return titlePainter.size;
|
|
}
|
|
|
|
extension TextLineHeight on TextStyle {
|
|
double get lineHeight => fontSize! * height!;
|
|
}
|