Created
May 28, 2020 23:02
-
-
Save vferreirati/57a2ee7fb35bc803121da1ddfd26cc0a to your computer and use it in GitHub Desktop.
MainText
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:agendador_mobile/src/core/resources/app_colors.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_screenutil/screenutil.dart'; | |
class MainText extends StatelessWidget { | |
final String text; | |
final FontWeight fontWeight; | |
final TextSize textSize; | |
final Color textColor; | |
final bool allCaps; | |
final TextAlign textAlign; | |
final int maxLines; | |
final TextOverflow overflow; | |
MainText.normal({ | |
@required this.text, | |
this.textColor = AppColors.LABEL_WHITE, | |
this.textSize = TextSize.P, | |
this.allCaps = false, | |
this.textAlign = TextAlign.start, | |
this.maxLines, | |
this.overflow | |
}) : fontWeight = FontWeight.normal; | |
MainText.light({ | |
@required this.text, | |
this.textColor = AppColors.LABEL_WHITE, | |
this.textSize = TextSize.P, | |
this.allCaps = false, | |
this.textAlign = TextAlign.start, | |
this.maxLines, | |
this.overflow | |
}) : fontWeight = FontWeight.w300; | |
MainText.medium({ | |
@required this.text, | |
this.textColor = AppColors.LABEL_WHITE, | |
this.textSize = TextSize.P, | |
this.allCaps = false, | |
this.textAlign = TextAlign.start, | |
this.maxLines, | |
this.overflow, | |
}) : fontWeight = FontWeight.w500; | |
MainText.heavy({ | |
@required this.text, | |
this.textColor = AppColors.LABEL_WHITE, | |
this.textSize = TextSize.P, | |
this.allCaps = false, | |
this.textAlign = TextAlign.start, | |
this.maxLines, | |
this.overflow, | |
}) : fontWeight = FontWeight.w800; | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Text( | |
allCaps ? text.toUpperCase() : text, | |
textAlign: textAlign, | |
maxLines: maxLines, | |
overflow: overflow, | |
style: TextStyle( | |
fontWeight: fontWeight, | |
fontFamily: 'Avenir', | |
fontSize: ScreenUtil().setSp(_getFontSize()), | |
color: textColor, | |
), | |
), | |
); | |
} | |
double _getFontSize() { | |
double sizeToReturn; | |
switch (textSize) { | |
case TextSize.H1: | |
sizeToReturn = 50; | |
break; | |
case TextSize.H2: | |
sizeToReturn = 37; | |
break; | |
case TextSize.H3: | |
sizeToReturn = 28; | |
break; | |
case TextSize.H4: | |
sizeToReturn = 21; | |
break; | |
case TextSize.P: | |
sizeToReturn = 16; | |
break; | |
case TextSize.CAPTION: | |
sizeToReturn = 12; | |
break; | |
case TextSize.M: | |
sizeToReturn = 9; | |
break; | |
} | |
return sizeToReturn; | |
} | |
} | |
enum TextSize { H1, H2, H3, H4, P, CAPTION, M } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment