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

189 lines
4.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
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,
buttonTitleText // risen button title text,
2020-12-08 21:26:51 +02:00
}
class BrandText extends StatelessWidget {
2021-02-15 20:58:29 +02:00
const BrandText(
this.text, {
2021-03-15 17:39:44 +02:00
Key? key,
2021-02-15 20:58:29 +02:00
this.style,
2021-03-15 17:39:44 +02:00
required this.type,
2021-02-15 20:58:29 +02:00
this.overflow,
this.softWrap,
this.textAlign,
}) : super(key: key);
2020-12-08 21:26:51 +02:00
2021-03-15 17:39:44 +02:00
final String? text;
final TextStyle? style;
2020-12-08 21:26:51 +02:00
final TextType type;
2021-03-15 17:39:44 +02:00
final TextOverflow? overflow;
final bool? softWrap;
final TextAlign? textAlign;
2020-12-08 21:26:51 +02:00
factory BrandText.h1(
2021-03-15 17:39:44 +02:00
String? text, {
TextStyle? style,
TextOverflow? overflow,
bool? softWrap,
2020-12-08 21:26:51 +02:00
}) =>
BrandText(
text,
type: TextType.h1,
style: style,
);
2021-01-06 19:35:57 +02:00
2021-03-15 17:39:44 +02:00
factory BrandText.onboardingTitle(String text, {TextStyle? style}) =>
2021-01-06 19:35:57 +02:00
BrandText(
text,
type: TextType.onboardingTitle,
style: style,
);
2021-03-15 17:39:44 +02:00
factory BrandText.h2(String? text, {TextStyle? style}) => BrandText(
2020-12-08 21:26:51 +02:00
text,
type: TextType.h2,
style: style,
);
2021-03-15 17:39:44 +02:00
factory BrandText.h3(String text, {TextStyle? style, 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
);
2021-03-26 15:38:39 +02:00
factory BrandText.h4(
String? text, {
TextStyle? style,
TextAlign? textAlign,
}) =>
BrandText(
2020-12-08 21:26:51 +02:00
text,
type: TextType.h4,
style: style,
2021-03-26 15:38:39 +02:00
textAlign: textAlign,
);
factory BrandText.h5(
String? text, {
TextStyle? style,
TextAlign? textAlign,
}) =>
BrandText(
text,
type: TextType.h5,
style: style,
textAlign: textAlign,
2020-12-08 21:26:51 +02:00
);
2021-03-15 17:39:44 +02:00
factory BrandText.body1(String? text, {TextStyle? style}) => BrandText(
2020-12-08 21:26:51 +02:00
text,
type: TextType.body1,
style: style,
);
2021-03-15 17:39:44 +02:00
factory BrandText.body2(String? text, {TextStyle? style}) => BrandText(
2020-12-08 21:26:51 +02:00
text,
type: TextType.body2,
style: style,
);
2021-03-15 17:39:44 +02:00
factory BrandText.medium(String? text,
{TextStyle? style, TextAlign? textAlign}) =>
2021-02-15 20:58:29 +02:00
BrandText(
text,
type: TextType.medium,
style: style,
textAlign: textAlign,
);
2021-03-15 17:39:44 +02:00
factory BrandText.small(String text, {TextStyle? style}) => BrandText(
2020-12-08 21:26:51 +02:00
text,
type: TextType.small,
style: style,
);
2021-03-15 17:39:44 +02:00
factory BrandText.buttonTitleText(String? text, {TextStyle? style}) =>
2021-02-15 20:58:29 +02:00
BrandText(
text,
type: TextType.buttonTitleText,
style: style,
);
2020-12-08 21:26:51 +02:00
@override
Text build(BuildContext context) {
2021-03-18 02:55:38 +02:00
TextStyle style;
2020-12-08 21:26:51 +02:00
var isDark = Theme.of(context).brightness == Brightness.dark;
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-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,
overflow: overflow,
softWrap: softWrap,
2021-01-06 19:35:57 +02:00
textAlign: textAlign,
2020-12-08 21:26:51 +02:00
);
}
}