48 lines
1.9 KiB
Dart
48 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class LimitedFontSizeUtil {
|
|
static double getCalculateFontSize(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;
|
|
}
|
|
|
|
static double getBodyFontSize(BuildContext context) {
|
|
final textScaler = MediaQuery.textScalerOf(context);
|
|
final double scaledFontSize = 12 * textScaler.scale(1);
|
|
return scaledFontSize > 12 ? 10 : scaledFontSize;
|
|
}
|
|
|
|
static double getInputFontSize(BuildContext context) {
|
|
final textScaler = MediaQuery.textScalerOf(context);
|
|
final double scaledFontSize = 12 * textScaler.scale(1);
|
|
return scaledFontSize > 12 ? 10 : scaledFontSize;
|
|
}
|
|
|
|
static double getHeaderFontSize(BuildContext context) {
|
|
final textScaler = MediaQuery.textScalerOf(context);
|
|
final double scaledFontSize = 16 * textScaler.scale(1);
|
|
return scaledFontSize > 16 ? 14 : scaledFontSize;
|
|
}
|
|
|
|
static double getSubHeaderFontSize(BuildContext context) {
|
|
final textScaler = MediaQuery.textScalerOf(context);
|
|
final double scaledFontSize = 14 * textScaler.scale(1);
|
|
return scaledFontSize > 14 ? 12 : scaledFontSize;
|
|
}
|
|
}
|