import 'package:flutter/material.dart'; import 'package:flutter_app/bootstrap/helpers.dart'; import 'package:flutter_app/resources/themes/styles/color_styles.dart'; extension NyText on Text { /// Set the Style to use [displayLarge]. Text displayLarge(BuildContext context) { return setStyle(Theme.of(context).textTheme.displayLarge); } /// Set the Style to use [displayMedium]. Text displayMedium(BuildContext context) { return setStyle(Theme.of(context).textTheme.displayMedium); } /// Set the Style to use [displaySmall]. Text displaySmall(BuildContext context) { return setStyle(Theme.of(context).textTheme.displaySmall); } /// Set the Style to use [headlineLarge]. Text headingLarge(BuildContext context) { return setStyle(Theme.of(context).textTheme.headlineLarge); } /// Set the Style to use [headlineMedium]. Text headingMedium(BuildContext context) { return setStyle(Theme.of(context).textTheme.headlineMedium); } /// Set the Style to use [headlineSmall]. Text headingSmall(BuildContext context) { return setStyle(Theme.of(context).textTheme.headlineSmall); } /// Set the Style to use [titleLarge]. Text titleLarge(BuildContext context) { return setStyle(Theme.of(context).textTheme.titleLarge); } /// Set the Style to use [titleMedium]. Text titleMedium(BuildContext context) { return setStyle(Theme.of(context).textTheme.titleMedium); } /// Set the Style to use [titleSmall]. Text titleSmall(BuildContext context) { return setStyle(Theme.of(context).textTheme.titleSmall); } /// Set the Style to use [bodyLarge]. Text large(BuildContext context) { return setStyle(Theme.of(context).textTheme.bodyLarge); } /// Set the Style to use [bodyMedium]. Text medium(BuildContext context) { return setStyle(Theme.of(context).textTheme.bodyMedium); } /// Set the Style to use [bodySmall]. Text small(BuildContext context) { return setStyle(Theme.of(context).textTheme.bodySmall); } /// Make the font bold. Text fontWeightBold() { return copyWith(style: TextStyle(fontWeight: FontWeight.bold)); } /// Make the font light. Text fontWeightLight() { return copyWith(style: TextStyle(fontWeight: FontWeight.w300)); } /// Change the [style]. Text setStyle(TextStyle? style) => copyWith(style: style); /// Sets the color from your [ColorStyles] or [Color]. Text setColor( BuildContext context, Color Function(ColorStyles color) newColor, {String? themeId}) { return copyWith( style: TextStyle( color: newColor(ThemeColor.get(context, themeId: themeId)))); } /// Aligns text to the left. Text alignLeft() { return copyWith(textAlign: TextAlign.left); } /// Aligns text to the right. Text alignRight() { return copyWith(textAlign: TextAlign.right); } /// Aligns text to the center. Text alignCenter() { return copyWith(textAlign: TextAlign.center); } /// Aligns text to the center. Text setMaxLines(int maxLines) { return copyWith(maxLines: maxLines); } /// Change the [fontFamily]. Text setFontFamily(String fontFamily) => copyWith(style: TextStyle(fontFamily: fontFamily)); /// Helper to apply changes. Text copyWith( {Key? key, StrutStyle? strutStyle, TextAlign? textAlign, TextDirection? textDirection = TextDirection.ltr, Locale? locale, bool? softWrap, TextOverflow? overflow, double? textScaleFactor, int? maxLines, String? semanticsLabel, TextWidthBasis? textWidthBasis, TextStyle? style}) { return Text(data ?? "", key: key ?? this.key, strutStyle: strutStyle ?? this.strutStyle, textAlign: textAlign ?? this.textAlign, textDirection: textDirection ?? this.textDirection, locale: locale ?? this.locale, softWrap: softWrap ?? this.softWrap, overflow: overflow ?? this.overflow, textScaleFactor: textScaleFactor ?? this.textScaleFactor, maxLines: maxLines ?? this.maxLines, semanticsLabel: semanticsLabel ?? this.semanticsLabel, textWidthBasis: textWidthBasis ?? this.textWidthBasis, style: style != null ? this.style?.merge(style) ?? style : this.style); } }