flutter-freaccess-hub/lib/shared/utils/limited_text_size.dart

21 lines
1008 B
Dart

import 'package:flutter/material.dart';
class LimitedTextSizeUtil {
static double getLimitedBodyFontSize(BuildContext context, double baseFontSize, double maxFontSize, double limitedFontSize) {
final textScaler = MediaQuery.textScalerOf(context);
final double scaledFontSize = baseFontSize * textScaler.scale(1);
return scaledFontSize > maxFontSize ? limitedFontSize : scaledFontSize;
}
static double getNoResizeFont(BuildContext context, double baseFontSize) {
final textScaler = MediaQuery.textScalerOf(context);
final double noscaledFontSize = baseFontSize / textScaler.scale(1);
return noscaledFontSize;
}
static double getScaledSizedBoxSize(BuildContext context, double baseFontSize, double maxFontSize, double sizeIfExceeded, double sizeIfNotExceeded) {
final textScaler = MediaQuery.textScalerOf(context);
final double scaledFontSize = baseFontSize * textScaler.scale(1);
return scaledFontSize > maxFontSize ? sizeIfExceeded : sizeIfNotExceeded;
}
}