Files
MWClash/lib/common/measure.dart
2024-04-30 23:38:49 +08:00

69 lines
1.5 KiB
Dart

import 'package:fl_clash/common/common.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Measure {
Measure.of(this.context);
final _textScaleFactor =
WidgetsBinding.instance.platformDispatcher.textScaleFactor;
Size computeTextSize(Text text) {
final textPainter = TextPainter(
text: TextSpan(text: text.data, style: text.style),
maxLines: text.maxLines,
textScaler: TextScaler.linear(_textScaleFactor),
textDirection: text.textDirection ?? TextDirection.ltr,
)..layout();
return textPainter.size;
}
late BuildContext context;
double? _bodyMediumHeight;
double? _bodySmallHeight;
double? _labelSmallHeight;
double? _titleLargeHeight;
double get bodyMediumHeight{
_bodyMediumHeight ??= computeTextSize(
Text(
"",
style: context.textTheme.bodyMedium,
),
).height;
return _bodyMediumHeight!;
}
double get bodySmallHeight{
_bodySmallHeight ??= computeTextSize(
Text(
"",
style: context.textTheme.bodySmall,
),
).height;
return _bodySmallHeight!;
}
double get labelSmallHeight{
_labelSmallHeight ??= computeTextSize(
Text(
"",
style: context.textTheme.labelSmall,
),
).height;
return _labelSmallHeight!;
}
double get titleLargeHeight{
_titleLargeHeight ??= computeTextSize(
Text(
"",
style: context.textTheme.titleLarge,
),
).height;
return _titleLargeHeight!;
}
}