import 'package:flutter/material.dart';

class TextUtil extends StatelessWidget {
  final String text;
  final TextStyle? style;
  final TextAlign? textAlign;

  const TextUtil({
    Key? key,
    required this.text,
    this.style,
    this.textAlign,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var textScale = MediaQuery.textScalerOf(context);
    var scaledTextSize = textScale.scale(style?.fontSize ?? 14);
    double limitedTextSize = scaledTextSize > (style?.fontSize ?? 14) * 2
        ? (style?.fontSize ?? 14) * 2
        : scaledTextSize;

    return Text(
      text,
      style: style?.copyWith(
        fontSize: limitedTextSize,
      ),
      textAlign: textAlign ?? TextAlign.start,
    );
  }
}
