selfprivacy.org.app/lib/ui/components/brand_text/brand_text.dart

239 lines
5.8 KiB
Dart
Raw Normal View History

2020-12-08 21:26:51 +02:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/config/text_themes.dart';
2021-07-29 08:24:42 +03:00
export 'package:selfprivacy/utils/extensions/text_extensions.dart';
2020-12-08 21:26:51 +02:00
2022-09-14 18:14:55 +03:00
// TODO: Delete this file
2020-12-08 21:26:51 +02:00
enum TextType {
h1, // right now only at onboarding and opened providers
h2, // cards titles
h3, // titles in about page
h4, // caption
2021-03-26 15:38:39 +02:00
h5, // Table data
2020-12-08 21:26:51 +02:00
body1, // normal
body2, // with opacity
2021-01-06 19:35:57 +02:00
medium,
small,
2021-02-15 20:58:29 +02:00
onboardingTitle,
2021-09-29 21:28:47 +03:00
buttonTitleText, // risen button title text,
h4Underlined,
2020-12-08 21:26:51 +02:00
}
class BrandText extends StatelessWidget {
2022-06-05 22:36:32 +03:00
factory BrandText.h4(
final String? text, {
final TextStyle? style,
final TextAlign? textAlign,
2020-12-08 21:26:51 +02:00
}) =>
BrandText(
text,
2022-06-05 22:36:32 +03:00
type: TextType.h4,
2020-12-08 21:26:51 +02:00
style: style,
2022-06-05 22:36:32 +03:00
softWrap: true,
overflow: TextOverflow.ellipsis,
maxLines: 2,
textAlign: textAlign,
2020-12-08 21:26:51 +02:00
);
2021-01-06 19:35:57 +02:00
factory BrandText.onboardingTitle(
final String text, {
final TextStyle? style,
}) =>
2021-01-06 19:35:57 +02:00
BrandText(
text,
type: TextType.onboardingTitle,
style: style,
);
factory BrandText.h3(
final String text, {
final TextStyle? style,
final TextAlign? textAlign,
}) =>
2021-02-15 20:58:29 +02:00
BrandText(
2020-12-08 21:26:51 +02:00
text,
type: TextType.h3,
style: style,
2021-02-15 20:58:29 +02:00
textAlign: textAlign,
overflow: TextOverflow.ellipsis,
2020-12-08 21:26:51 +02:00
);
2022-06-05 22:36:32 +03:00
factory BrandText.h4Underlined(
final String? text, {
final TextStyle? style,
final TextAlign? textAlign,
2021-03-26 15:38:39 +02:00
}) =>
BrandText(
2020-12-08 21:26:51 +02:00
text,
2022-06-05 22:36:32 +03:00
type: TextType.h4Underlined,
2020-12-08 21:26:51 +02:00
style: style,
2021-09-29 21:28:47 +03:00
softWrap: true,
overflow: TextOverflow.ellipsis,
maxLines: 2,
textAlign: textAlign,
);
2022-06-05 22:36:32 +03:00
factory BrandText.h1(
final String? text, {
final TextStyle? style,
final TextOverflow? overflow,
final bool? softWrap,
2021-09-29 21:28:47 +03:00
}) =>
BrandText(
text,
2022-06-05 22:36:32 +03:00
type: TextType.h1,
2021-09-29 21:28:47 +03:00
style: style,
2021-03-26 15:38:39 +02:00
);
2022-06-05 22:36:32 +03:00
factory BrandText.h2(
final String? text, {
final TextStyle? style,
final TextAlign? textAlign,
2021-03-26 15:38:39 +02:00
}) =>
BrandText(
text,
2022-06-05 22:36:32 +03:00
type: TextType.h2,
2021-03-26 15:38:39 +02:00
style: style,
textAlign: textAlign,
2020-12-08 21:26:51 +02:00
);
factory BrandText.body1(final String? text, {final TextStyle? style}) =>
BrandText(
2020-12-08 21:26:51 +02:00
text,
type: TextType.body1,
style: style,
);
factory BrandText.small(final String text, {final TextStyle? style}) =>
BrandText(
2022-06-05 22:36:32 +03:00
text,
type: TextType.small,
style: style,
);
factory BrandText.body2(final String? text, {final TextStyle? style}) =>
BrandText(
2020-12-08 21:26:51 +02:00
text,
type: TextType.body2,
style: style,
);
factory BrandText.buttonTitleText(
final String? text, {
final TextStyle? style,
}) =>
2021-02-15 20:58:29 +02:00
BrandText(
text,
2022-06-05 22:36:32 +03:00
type: TextType.buttonTitleText,
2021-02-15 20:58:29 +02:00
style: style,
);
2022-06-05 22:36:32 +03:00
factory BrandText.h5(
final String? text, {
final TextStyle? style,
final TextAlign? textAlign,
}) =>
BrandText(
2020-12-08 21:26:51 +02:00
text,
2022-06-05 22:36:32 +03:00
type: TextType.h5,
2020-12-08 21:26:51 +02:00
style: style,
2022-06-05 22:36:32 +03:00
textAlign: textAlign,
2020-12-08 21:26:51 +02:00
);
factory BrandText.medium(
final String? text, {
final TextStyle? style,
final TextAlign? textAlign,
}) =>
2021-02-15 20:58:29 +02:00
BrandText(
text,
2022-06-05 22:36:32 +03:00
type: TextType.medium,
2021-02-15 20:58:29 +02:00
style: style,
2022-06-05 22:36:32 +03:00
textAlign: textAlign,
2021-02-15 20:58:29 +02:00
);
2022-06-05 22:36:32 +03:00
const BrandText(
this.text, {
required this.type,
super.key,
this.style,
2022-06-05 22:36:32 +03:00
this.overflow,
this.softWrap,
this.textAlign,
this.maxLines,
});
final String? text;
final TextStyle? style;
final TextType type;
final TextOverflow? overflow;
final bool? softWrap;
final TextAlign? textAlign;
final int? maxLines;
2020-12-08 21:26:51 +02:00
@override
2022-06-05 22:36:32 +03:00
Text build(final BuildContext context) {
2021-03-18 02:55:38 +02:00
TextStyle style;
2022-06-05 22:36:32 +03:00
final bool isDark = Theme.of(context).brightness == Brightness.dark;
2020-12-08 21:26:51 +02:00
switch (type) {
case TextType.h1:
style = isDark
? headline1Style.copyWith(color: Colors.white)
: headline1Style;
break;
case TextType.h2:
style = isDark
? headline2Style.copyWith(color: Colors.white)
: headline2Style;
break;
case TextType.h3:
style = isDark
? headline3Style.copyWith(color: Colors.white)
: headline3Style;
break;
case TextType.h4:
style = isDark
? headline4Style.copyWith(color: Colors.white)
: headline4Style;
break;
2021-09-29 21:28:47 +03:00
case TextType.h4Underlined:
style = isDark
? headline4UnderlinedStyle.copyWith(color: Colors.white)
: headline4UnderlinedStyle;
break;
2021-03-26 15:38:39 +02:00
case TextType.h5:
style = isDark
? headline5Style.copyWith(color: Colors.white)
: headline5Style;
break;
2020-12-08 21:26:51 +02:00
case TextType.body1:
style = isDark ? body1Style.copyWith(color: Colors.white) : body1Style;
break;
case TextType.body2:
style = isDark
? body2Style.copyWith(color: Colors.white.withOpacity(0.6))
: body2Style;
break;
case TextType.small:
style = isDark ? smallStyle.copyWith(color: Colors.white) : smallStyle;
break;
2021-01-06 19:35:57 +02:00
case TextType.onboardingTitle:
style = isDark
? onboardingTitle.copyWith(color: Colors.white)
: onboardingTitle;
break;
case TextType.medium:
style =
isDark ? mediumStyle.copyWith(color: Colors.white) : mediumStyle;
break;
2021-02-15 20:58:29 +02:00
case TextType.buttonTitleText:
style = !isDark
? buttonTitleText.copyWith(color: Colors.white)
: buttonTitleText;
break;
2020-12-08 21:26:51 +02:00
}
if (this.style != null) {
style = style.merge(this.style);
}
return Text(
2021-03-15 17:39:44 +02:00
text!,
2020-12-08 21:26:51 +02:00
style: style,
2021-09-29 21:28:47 +03:00
maxLines: maxLines,
2020-12-08 21:26:51 +02:00
overflow: overflow,
softWrap: softWrap,
2021-01-06 19:35:57 +02:00
textAlign: textAlign,
2020-12-08 21:26:51 +02:00
);
}
}