Please help me with simple question about material_ui - material-ui

I just created a react app and installed material ui and in public folder I have include link to roboto font, but it is not applied.
I see only system font (dejVu serif ). If I have override for example muiToolbar and type here fonfamaly roboto it is works, but in default as I wrote it doesn't. How to fix this?

To add a font to react regardless of using material-ui or not, You need to add the CDN of the font inside the index.html file, or You can import it using CSS.
Here is a helpful resource for you

Do you have a custom theme file, a file that you customized the application theme?
Check the typography field in that file, maybe some other fonts were added there without your understanding.
Here is the default theme typography field:
typography: Object
htmlFontSize: 16
pxToRem: f ()
round: f S()
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontSize: 14
fontWeightLight: 300
fontWeightRegular: 400
fontWeightMedium: 500
fontWeightBold: 700
h1: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 300
fontSize: "6rem"
lineHeight: 1.167
letterSpacing: "-0.01562em"
h2: fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 300
fontSize: "3.75rem"
lineHeight: 1.2
letterSpacing: "-0.00833em"
h3: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 400
fontSize: "3rem"
lineHeight: 1.167
letterSpacing: "0em"
h4: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 400
fontSize: "2.125rem"
lineHeight: 1.235
letterSpacing: "0.00735em"
h5: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 400
fontSize: "1.5rem"
lineHeight: 1.334
letterSpacing: "0em"
h6: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 500
fontSize: "1.25rem"
lineHeight: 1.6
letterSpacing: "0.0075em"
subtitle1: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 400
fontSize: "1rem"
lineHeight: 1.75
letterSpacing: "0.00938em"
subtitle2: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 500
fontSize: "0.875rem"
lineHeight: 1.57
letterSpacing: "0.00714em"
body1: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 400
fontSize: "1rem"
lineHeight: 1.5
letterSpacing: "0.00938em"
body2: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 400
fontSize: "0.875rem"
lineHeight: 1.43
letterSpacing: "0.01071em"
button: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 500
fontSize: "0.875rem"
lineHeight: 1.75
letterSpacing: "0.02857em"
textTransform: "uppercase"
caption: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 400
fontSize: "0.75rem"
lineHeight: 1.66
letterSpacing: "0.03333em"
overline: Object
fontFamily: ""Roboto", "Helvetica", "Arial", sans-serif"
fontWeight: 400
fontSize: "0.75rem"
lineHeight: 2.66
letterSpacing: "0.08333em"
textTransform: "uppercase"

Related

Using dimens in font size as design

I want to create a text base TextStyle to apply the image above, but I read some suggestions related to dimes then they advise me to use flutter_screenutil 5.0.3 package.
But it got errors:
LateInitializationError: Field '\_minTextAdapt#647084504' has not been initialized.
Also using this library I'm not sure it can define the screen well when rotating the screen horizontally.
My code in app_theme.dart:
class AppText extends TextStyle {
static TextStyle get text12 => TextStyle(
// TODO this has an error when I using library dimens
fontSize: 12.sp,
fontFamily: Platform.isIOS ? Fonts.avenirNextRegular : Fonts.robotoRegular,
fontWeight: FontWeight.normal,
color: AppColor.mineShaft,
);
static TextStyle get text13 => TextStyle(
fontSize: 13,
fontFamily: Platform.isIOS ? Fonts.avenirNextRegular : Fonts.robotoRegular,
fontWeight: FontWeight.normal,
color: AppColor.mineShaft,
);
static TextStyle get text16 => TextStyle(
fontSize: 16,
fontFamily: Platform.isIOS ? Fonts.avenirNextRegular : Fonts.robotoRegular,
fontWeight: FontWeight.normal,
color: AppColor.mineShaft,
);
static TextStyle get text18 => TextStyle(
fontSize: 18,
fontFamily: Platform.isIOS ? Fonts.avenirNextRegular : Fonts.robotoRegular,
fontWeight: FontWeight.normal,
color: AppColor.mineShaft,
);
static TextStyle get text20 => TextStyle(
fontSize: 20,
fontFamily: Platform.isIOS ? Fonts.avenirNextRegular : Fonts.robotoRegular,
fontWeight: FontWeight.normal,
color: AppColor.mineShaft,
);
static TextStyle get text22 => TextStyle(
fontSize: 22,
fontFamily: Platform.isIOS ? Fonts.avenirNextRegular : Fonts.robotoRegular,
fontWeight: FontWeight.normal,
color: AppColor.mineShaft,
);
}
How can I create base fontSize text and apply it to dimens app text according to the design font above?

Quicksand bold not rendering as expected when bold

As in picture R & A word is...
Here are my code as in picture below
child: Text(
'RENTAL SUMMARY',
style: TextStyle(
fontFamily: 'quicksand',
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
Please download the quicksand font from Google fonts. Add this to your pubspec yaml and try again. Maybe the ttf you have is corrupted

How to change Text Size of different Texts in my app in real time in Flutter

In my app, I made custom TextStyles for different purposes. I made variables for their respective sizes and initialized them like this -
double fontSize1=24;
double fontSize2=20;
double fontSize3=18;
double bodyText1Size=16;
double bodyText2Size=14;
double bodyText3Size=12;
double buttonTextStyleSize=16;
double linkStyleSize=12;
var headingStyle1 = TextStyle(
fontSize: fontSize1,
fontWeight: FontWeight.bold,
color: Colors.black,
);
var headingStyle2 = TextStyle(
fontSize: fontSize2,
fontWeight: FontWeight.bold,
color: Colors.black,
);
var headingStyle3 = TextStyle(
fontSize: fontSize2,
fontWeight: FontWeight.w600,
color: Colors.black,
);
var headingStyle4 = TextStyle(
fontSize: fontSize3,
fontWeight: FontWeight.w600,
color: Colors.black,
);
var bodyText1 = TextStyle(
fontSize: bodyText1Size,
fontWeight: FontWeight.w400,
color: Colors.black,
);
var bodyText2 = TextStyle(
fontSize: bodyText2Size,
fontWeight: FontWeight.w400,
color: Colors.black,
);
var bodyText3 = TextStyle(
fontSize: bodyText3Size,
fontWeight: FontWeight.w400,
color: tertiaryTextColor,
);
var buttonTextStyle = TextStyle(
fontSize: buttonTextStyleSize,
fontWeight: FontWeight.bold,
color: Colors.black,
);
var linkStyle = TextStyle(
fontSize: linkStyleSize,
fontWeight: FontWeight.w600,
color: Colors.black,
);
And then, used them in my main.dart in my Material App's TextTheme like this -
textTheme: TextTheme(
headline1: headingStyle1,
headline2: headingStyle2,
headline3: headingStyle3,
headline4: headingStyle4,
headline6: bodyText3,
bodyText1: bodyText1,
bodyText2: bodyText2,
button: buttonTextStyle,
caption: linkStyle,
),
Now, I am using this everywhere in my app, for eg -
Text(
"These settings will be applied all across the app",
style: Theme.of(context)
.textTheme
.bodyText2!
.apply(color: tertiaryTextColor),
),
Now, I want to change their sizes from my UI, and for that I created two Buttons and in them, just for now I increased/decreased their sizes. I used setState to change their sizes like this -
InkWell(
onTap: () {
setState(() {
fontSize1--;
fontSize2--;
fontSize3--;
});
print("Font Sizes increased by 1");
print("Font Sizes 1 = $fontSize1");
print("Font Sizes 2 = $fontSize2");
print("Font Sizes 3 = $fontSize3");
},
child: Text(
"-",
style: Theme.of(context)
.textTheme
.headline2!
.apply(color: secondaryTextColor),
),
),
Now, in my logs, as i printed, their sizes are changing but UI is not. Why? Can you please tell me a solution for this?
You can call textTheme with .copy and change what you want for example color or size or .... etc
Text(
"These settings will be applied all across the app",
style: Theme.of(context)
.textTheme
.bodyText2!
// .apply(color: tertiaryTextColor), comment this
.copyWith(color: tertiaryTextColor), // add this line for color attribute or any else
),
I think that you have to change the headingStyle variable and not the fontSize. Because the headingStyle variable has been set with the current fontSize, even though you change the fontSize, the headingStyle does not change because it is a variable. You can change the headingStyle from variable to method like this:
TextStyle get headingStyle1 => TextStyle(
fontSize: fontSize1,
fontWeight: FontWeight.bold,
color: Colors.black,
);
with this code, everytime you will define a textStyle, it will create and return the textStyle, so while you update the state, It will get the new fontSize.
Also, instead of changing the fontSize, you can change the headingStyle like this:
onTap() {
setState(() {
headingStyle1 = TextStyle(
fontSize: --fontSize1,
fontWeight: FontWeight.bold,
color: Colors.black,
);
headingStyle2 = TextStyle(
fontSize: --fontSize2,
fontWeight: FontWeight.bold,
color: Colors.black,
);
headingStyle3 = TextStyle(
fontSize: --fontSize2,
fontWeight: FontWeight.w600,
color: Colors.black,
);
headingStyle4 = TextStyle(
fontSize: --fontSize3,
fontWeight: FontWeight.w600,
color: Colors.black,
);
});
print("Font Sizes increased by 1");
print("Font Sizes 1 = $fontSize1");
print("Font Sizes 2 = $fontSize2");
print("Font Sizes 3 = $fontSize3");
}

Flutter: base.copyWith() applying custom theme name or property

TextTheme _basicTextTheme(TextTheme base) {
return base.copyWith(
headline1: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
headline6: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
bodyText1: GoogleFonts.lato(
fontSize: 20, color: Colors.orange),
bodyText2: GoogleFonts.lato(
fontSize: 15.0,
));
}
I have succeed to apply this to my themeData. Is there anyway that I can create a custom field to it? Like
linkText: GoogleFonts.lato(fontSize: 20)
So far, I have distinguished using headline and bodyText 1 2 3 but then it is a bit confusing right now. I want to create a custom name that I can use.
You can use extension on TextTheme
extension CustomTextStyles on TextTheme {
TextStyle get linkText {
return TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.w600,
);
}
TextStyle get buttonText{
return TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w400,
);
}
}

How to override theme style in flutter

Hi i need text style for example bodyText3,like this
bodyText3: TextStyle(
fontSize: 16,
height: 1.5,
fontWeight: FontWeight.w600,
color: MyColors.black)
but in flutter we have only this styles.
headline1,
headline2,
headline3,
headline4,
headline5,
headline6,
subtitle1,
subtitle2,
bodyText1,
bodyText2,
caption,
What should i do to add my new style ?
Create a Constant to define the style
const TextStyle bodyText3 = TextStyle(
fontSize: 14,
color: darkGrey,
fontWeight: FontWeight.w700,
);
Use this constant in your Text's style property
Text(
'No',
style: bodyText3,
),