You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/extensions/text_extensions.dart

187 lines
6.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:lottie/lottie.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import '../new_views/app_style/app_color.dart';
extension TextStyles on String {
Text heading1(BuildContext context) => getTextWithStyle(this, AppTextStyles.heading1, context.isDark ? AppColor.backgroundLight : AppColor.neutral70);
Text heading2(BuildContext context) => getTextWithStyle(this, AppTextStyles.heading2, context.isDark ? AppColor.neutral30 : AppColor.neutral50);
Text heading3(BuildContext context) => getTextWithStyle(this, AppTextStyles.heading3, context.isDark ? AppColor.neutral30 : AppColor.neutral50);
Text heading4(BuildContext context) => getTextWithStyle(this, AppTextStyles.heading4, context.isDark ? AppColor.neutral30 : AppColor.neutral50);
Text heading5(BuildContext context) => getTextWithStyle(this, AppTextStyles.heading5, context.isDark ? AppColor.neutral30 : AppColor.neutral50);
Text bottomSheetHeadingTextStyle(BuildContext context) => getTextWithStyle(this, AppTextStyles.bottomSheetHeadingTextStyle, context.isDark ? AppColor.neutral30 : AppColor.black20);
Text customHeadingText(BuildContext context) => getTextWithStyle(this, AppTextStyles.customHeadingText, context.isDark ? AppColor.neutral30 : AppColor.neutral50);
Text heading6(BuildContext context) => getTextWithStyle(this, AppTextStyles.heading6, context.isDark ? AppColor.neutral30 : AppColor.neutral50);
Text bodyText(BuildContext context) => getTextWithStyle(this, AppTextStyles.bodyText, context.isDark ? AppColor.neutral10 : AppColor.neutral20);
Text bodyText2(BuildContext context) => getTextWithStyle(this, AppTextStyles.bodyText2, context.isDark ? AppColor.neutral10 : AppColor.neutral20);
Text tinyFont(BuildContext context) => getTextWithStyle(this, AppTextStyles.tinyFont, context.isDark ? AppColor.neutral10 : AppColor.neutral120);
Text overline(BuildContext context) => getTextWithStyle(this, AppTextStyles.overline, context.isDark ? AppColor.neutral10 : AppColor.neutral20);
Text getTextWithStyle(String string, TextStyle style, Color color) => Text(string ?? "", style: style.copyWith(color: color));
}
extension CustomText on Text {
Text custom({Color? color, FontWeight? fontWeight, TextAlign? align, double? fontSize, double? lineHeight, double? letterSpacing}) {
return Text(
data!,
textAlign: align,
style: style?.copyWith(
color: color,
height: lineHeight,
letterSpacing: letterSpacing,
fontSize: fontSize,
fontWeight: fontWeight,
),
);
}
}
abstract class AppTextStyles {
static final TextStyle heading1 = TextStyle(
fontSize: 54.toScreenWidth,
fontWeight: FontWeight.w500,
letterSpacing: -0.81,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle heading2 = TextStyle(
fontSize: 28.toScreenWidth,
fontWeight: FontWeight.w700,
letterSpacing: -0.56,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle heading3 = TextStyle(
fontSize: 24.toScreenWidth,
fontWeight: FontWeight.w700,
letterSpacing: -0.12,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle heading4 = TextStyle(
fontSize: 21.toScreenWidth,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle heading5 = TextStyle(
fontSize: 19.toScreenWidth,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle bottomSheetHeadingTextStyle = TextStyle(
fontSize: 21.toScreenWidth,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static const TextStyle customHeadingText = TextStyle(
fontFamily: 'Poppins',
fontSize: 27,
// Font size in logical pixels
fontWeight: FontWeight.w500,
// Equivalent to font-weight: 500
height: 31 / 27,
// Line height (in Flutter, it's a multiplier of font size)
letterSpacing: -0.04 * 27,
// Letter spacing, converted to logical pixels
color: Colors.black, // Set your desired text color
);
static final TextStyle heading6 = TextStyle(
fontSize: 16.toScreenWidth,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle bodyText = TextStyle(
fontSize: 14.toScreenWidth,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle bodyText2 = TextStyle(
fontSize: 12.toScreenWidth,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle tinyFont = TextStyle(
fontSize: 11.toScreenWidth,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle textFieldLabelStyle= TextStyle(
fontSize: 11.toScreenWidth,
fontWeight: FontWeight.w500,
color: AppColor.neutral20,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle tinyFont2 = TextStyle(
fontSize: 10.toScreenWidth,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
static final TextStyle overline = TextStyle(
fontSize: 9.toScreenWidth,
fontWeight: FontWeight.w500,
letterSpacing: 0.05,
fontStyle: FontStyle.normal,
decoration: TextDecoration.none,
);
}
extension CapExtension on String {
String get toCamelCase => "${this[0].toUpperCase()}${substring(1)}";
String get inCaps => '${this[0].toUpperCase()}${substring(1)}';
String get allInCaps => toUpperCase();
String get cleanupWhitespace => this;//replaceAll(RegExp(r"\s+"), " ");
String get capitalizeFirstOfEach => this;
//trim().isNotEmpty
// ? trim().toLowerCase().split(" ").map((str) {
// return str.trim()?.inCaps ?? "";
// }).join(" ")
// : "";
}
extension FilesExtension on String {
SvgPicture toSvgAsset({int? width, int? height, Color? color, BoxFit fit = BoxFit.contain}) =>
SvgPicture.asset("assets/images/$this.svg", width: width?.toScreenWidth, height: height?.toScreenHeight, color: color, fit: fit);
Image toPngAsset({int? width, int? height, Color? color, BoxFit fit = BoxFit.contain}) =>
Image.asset("assets/images/$this.png", width: width?.toScreenWidth, height: height?.toScreenHeight, color: color, fit: fit);
LottieBuilder toLottieAsset({int? width, int? height, BoxFit fit = BoxFit.contain, bool repeat = true}) =>
Lottie.asset("assets/lottie/$this.json", width: width?.toScreenWidth, height: height?.toScreenHeight, fit: fit, repeat: repeat);
}