Flutter: How to set line height property of text to ThemeData - flutter

How can I set the line-height globally inside ThemeData?
theme: ThemeData(
brightness: Brightness.light,
accentColor: myAccentColor,
primaryColor: myPrimaryColor,
fontFamily: 'Ubuntu',
buttonTheme: ThemeData.light().buttonTheme.copyWith(
buttonColor: myPrimaryColor,
textTheme: ButtonTextTheme.primary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)),
),
scaffoldBackgroundColor: myBackgroundWhite,
cardColor: myBackgroundWhite,
textSelectionColor: myGreyTextColor,
cursorColor: myAccentColor,
cupertinoOverrideTheme: CupertinoThemeData(
primaryColor: myAccentColor,
),
errorColor: myErrorColorRed,
)

We cant set the line-height (property name: height) directly from ThemeData.
The best practice for handling text style is by using material type system guidelines. See the section "Material Text Scale: Modernizing Flutter Text Theming" from here.
So then on global ThemeData, you can use
theme: ThemeData(
brightness: Brightness.light,
accentColor: flujoAccentColor,
primaryColor: flujoPrimaryColor,
fontFamily: 'FiraSans',
textTheme: TextTheme(
headline5: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.w700,
fontStyle: FontStyle.normal,
),
bodyText1: TextStyle(
fontSize: 16.0,
fontStyle: FontStyle.normal,
letterSpacing: 0.5,
),
bodyText2: TextStyle(
fontSize: 14.0,
fontStyle: FontStyle.normal,
letterSpacing: 0.25,
height: 1.5,
),
subtitle1: TextStyle(
fontSize: 16.0,
fontStyle: FontStyle.normal,
letterSpacing: 0.15,
),
subtitle2: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
caption: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
overline: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w400,
letterSpacing: 0.25,
height: 1.5,
fontStyle: FontStyle.normal,
)),
Like this and on a Text widget, apply it like:
Text(
"Hello world!",
style: Theme.of(context).textTheme.bodyText1.copyWith(color: Colors.teal,),
);

Related

Use font suggested by material design

I'd like to use this font chosen from material design website into my Flutter mobile app. I've copied the code inside my main as follow.
But I have "undefined name GoogleFonts".
I've downloaded font from here : (https://fonts.google.com/noto/specimen/Noto+Sans?query=noto+sa) and copied the whole downloaded files *.ttf inside a font folder named GoogleFont, and of course added those lines of code inside pubspec.yaml
fonts:
- family: NotoSans
fonts:
- asset: GoogleFonts/NotoSans-Regular.ttf
Code inside main.dart:
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
textTheme: TextTheme(
headline1: GoogleFonts.notoSans(
fontSize: 94, fontWeight: FontWeight.w300, letterSpacing: -1.5),
headline2: GoogleFonts.notoSans(
fontSize: 59, fontWeight: FontWeight.w300, letterSpacing: -0.5),
headline3:
GoogleFonts.notoSans(fontSize: 47, fontWeight: FontWeight.w400),
headline4: GoogleFonts.notoSans(
fontSize: 33, fontWeight: FontWeight.w400, letterSpacing: 0.25),
headline5:
GoogleFonts.notoSans(fontSize: 24, fontWeight: FontWeight.w400),
headline6: GoogleFonts.notoSans(
fontSize: 20, fontWeight: FontWeight.w500, letterSpacing: 0.15),
subtitle1: GoogleFonts.notoSans(
fontSize: 16, fontWeight: FontWeight.w400, letterSpacing: 0.15),
subtitle2: GoogleFonts.notoSans(
fontSize: 14, fontWeight: FontWeight.w500, letterSpacing: 0.1),
bodyText1: GoogleFonts.notoSans(
fontSize: 16, fontWeight: FontWeight.w400, letterSpacing: 0.5),
bodyText2: GoogleFonts.notoSans(
fontSize: 14, fontWeight: FontWeight.w400, letterSpacing: 0.25),
button: GoogleFonts.notoSans(
fontSize: 14, fontWeight: FontWeight.w500, letterSpacing: 1.25),
caption: GoogleFonts.notoSans(
fontSize: 12, fontWeight: FontWeight.w400, letterSpacing: 0.4),
overline: GoogleFonts.notoSans(
fontSize: 10, fontWeight: FontWeight.w400, letterSpacing: 1.5),
),
),
home: LoginPage(),
);
}
}

TextStyle doesn't identify accentColor and returns the wrong color

In MaterialApp in theme, I am setting heeadline6's color with already set accentColor. But when I try to display text with headline6 textTheme, it gives me the wrong color, although every other parameter is correct.
theme: ThemeData(
accentColor: const Color(0xffAEB8C4),
textTheme: TextTheme(
headline6: TextStyle(
color: Theme.of(context).accentColor,
fontFamily: 'Lato',
fontStyle: FontStyle.normal,
fontSize: 50,
fontWeight: FontWeight.w900,
),
),
),
This is the color
And here is the code, Where I use headline6:
child: Text(
"RLabs",
style: Theme.of(context).textTheme.headline6,
),
And yet somehow I get the text with another color.
I suggest storing the constant accent color in a separate palette class.
Example -
Palette{
static final accentColor = Color(0xffAEB8C4);
}
Then
theme: ThemeData(
accentColor: Palette.accentColor,
textTheme: TextTheme(
headline6: TextStyle(
color: Palette.accentColor,
fontFamily: 'Lato',
fontStyle: FontStyle.normal,
fontSize: 50,
fontWeight: FontWeight.w900,
),
),
),
Please look at this answer to get clarification on why Theme.of(context) doesn't work in your specific case
You can give direct color to TextStyle.
theme: ThemeData(
accentColor: const Color(0xffAEB8C4),
textTheme: TextTheme(
headline6: TextStyle(
color: const Color(0xffAEB8C4),
fontFamily: 'Lato',
fontStyle: FontStyle.normal,
fontSize: 50,
fontWeight: FontWeight.w900,
),
),
),

How to set default font color in flutter?

I want to set the default font colour for the flutter app globally. I tried
ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'Gilroy',
textTheme: TextTheme(
bodyText1: TextStyle(),
bodyText2: TextStyle(),
).apply(
bodyColor: const Color(0xff22215B),
displayColor: const Color(0xff22215B),
),
),
Some text is coloured. but Text in Appbar is not applied automatically.
Apply this
ThemeData(
appBarTheme: AppBarTheme(
textTheme: Theme.of(context).textTheme.apply(
bodyColor: const Color(0xff22215B),
displayColor: const Color(0xff22215B),
),
),
textTheme: Theme.of(context).textTheme.apply(
bodyColor: const Color(0xff22215B),
displayColor: const Color(0xff22215B),
),
)
textTheme alone does not affect AppBar. You should use appBarTheme. Try this:
appBarTheme: AppBarTheme(
textTheme: TextTheme(
//...
).apply(
bodyColor: Color(0xff22215B), displayColor: Color(0xff22215B))),
Select your theme at https://rxlabz.github.io/panache_web/#/.
Download the total theme code as well from that website.
Sample Code default font color in flutter?
final ThemeData myTheme = ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.light,
primaryColor: Color( 0xff2196f3 ),
textTheme: TextTheme(
display4: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display3: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display2: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display1: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
headline: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
title: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subhead: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body2: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body1: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
caption: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
button: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subtitle: TextStyle(
color: Color( 0xff000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
overline: TextStyle(
color: Color( 0xff000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
),
primaryTextTheme: TextTheme(
display4: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display3: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display2: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display1: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
headline: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
title: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subhead: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body2: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body1: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
caption: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
button: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subtitle: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
overline: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
}
Sample Code Full:
import 'package:flutter/material.dart';
final ThemeData myTheme = ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.light,
primaryColor: Color( 0xff2196f3 ),
primaryColorBrightness: Brightness.dark,
primaryColorLight: Color( 0xffbbdefb ),
primaryColorDark: Color( 0xff1976d2 ),
accentColor: Color( 0xff2196f3 ),
accentColorBrightness: Brightness.dark,
canvasColor: Color( 0xfffafafa ),
scaffoldBackgroundColor: Color( 0xfffafafa ),
bottomAppBarColor: Color( 0xffffffff ),
cardColor: Color( 0xffffffff ),
dividerColor: Color( 0x1f000000 ),
highlightColor: Color( 0x66bcbcbc ),
splashColor: Color( 0x66c8c8c8 ),
selectedRowColor: Color( 0xfff5f5f5 ),
unselectedWidgetColor: Color( 0x8a000000 ),
disabledColor: Color( 0x61000000 ),
buttonColor: Color( 0xffe0e0e0 ),
toggleableActiveColor: Color( 0xff1e88e5 ),
secondaryHeaderColor: Color( 0xffe3f2fd ),
textSelectionColor: Color( 0xff90caf9 ),
cursorColor: Color( 0xff4285f4 ),
textSelectionHandleColor: Color( 0xff64b5f6 ),
backgroundColor: Color( 0xff90caf9 ),
dialogBackgroundColor: Color( 0xffffffff ),
indicatorColor: Color( 0xff2196f3 ),
hintColor: Color( 0x8a000000 ),
errorColor: Color( 0xffd32f2f ),
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme.normal,
minWidth: 88,
height: 36,
padding: EdgeInsets.only(top:0,bottom:0,left:16, right:16),
shape: RoundedRectangleBorder(
side: BorderSide(color: Color( 0xff000000 ), width: 0, style: BorderStyle.none, ),
borderRadius: BorderRadius.all(Radius.circular(2.0)),
)
,
alignedDropdown: false ,
buttonColor: Color( 0xffe0e0e0 ),
disabledColor: Color( 0x61000000 ),
highlightColor: Color( 0x29000000 ),
splashColor: Color( 0x1f000000 ),
focusColor: Color( 0x1f000000 ),
hoverColor: Color( 0x0a000000 ),
colorScheme: ColorScheme(
primary: Color( 0xff2196f3 ),
primaryVariant: Color( 0xff1976d2 ),
secondary: Color( 0xff2196f3 ),
secondaryVariant: Color( 0xff1976d2 ),
surface: Color( 0xffffffff ),
background: Color( 0xff90caf9 ),
error: Color( 0xffd32f2f ),
onPrimary: Color( 0xffffffff ),
onSecondary: Color( 0xffffffff ),
onSurface: Color( 0xff000000 ),
onBackground: Color( 0xffffffff ),
onError: Color( 0xffffffff ),
brightness: Brightness.light,
),
),
textTheme: TextTheme(
display4: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display3: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display2: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display1: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
headline: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
title: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subhead: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body2: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body1: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
caption: TextStyle(
color: Color( 0x8a000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
button: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subtitle: TextStyle(
color: Color( 0xff000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
overline: TextStyle(
color: Color( 0xff000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
),
primaryTextTheme: TextTheme(
display4: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display3: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display2: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display1: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
headline: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
title: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subhead: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body2: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body1: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
caption: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
button: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subtitle: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
overline: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
),
accentTextTheme: TextTheme(
display4: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display3: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display2: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
display1: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
headline: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
title: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subhead: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body2: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
body1: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
caption: TextStyle(
color: Color( 0xb3ffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
button: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
subtitle: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
overline: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
),
inputDecorationTheme: InputDecorationTheme(
labelStyle: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
helperStyle: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
hintStyle: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
errorStyle: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
errorMaxLines: null,
hasFloatingPlaceholder: true,
isDense: false,
contentPadding: EdgeInsets.only(top:12,bottom:12,left:0, right:0),
isCollapsed : false,
prefixStyle: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
suffixStyle: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
counterStyle: TextStyle(
color: Color( 0xdd000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
filled: false,
fillColor: Color( 0x00000000 ),
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color( 0xff000000 ), width: 1, style: BorderStyle.solid, ),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color( 0xff000000 ), width: 1, style: BorderStyle.solid, ),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
focusedErrorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color( 0xff000000 ), width: 1, style: BorderStyle.solid, ),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
disabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color( 0xff000000 ), width: 1, style: BorderStyle.solid, ),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color( 0xff000000 ), width: 1, style: BorderStyle.solid, ),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color( 0xff000000 ), width: 1, style: BorderStyle.solid, ),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
),
iconTheme: IconThemeData(
color: Color( 0xdd000000 ),
opacity: 1,
size: 24,
),
primaryIconTheme: IconThemeData(
color: Color( 0xffffffff ),
opacity: 1,
size: 24,
),
accentIconTheme: IconThemeData(
color: Color( 0xffffffff ),
opacity: 1,
size: 24,
),
sliderTheme: SliderThemeData(
activeTrackColor: null,
inactiveTrackColor: null,
disabledActiveTrackColor: null,
disabledInactiveTrackColor: null,
activeTickMarkColor: null,
inactiveTickMarkColor: null,
disabledActiveTickMarkColor: null,
disabledInactiveTickMarkColor: null,
thumbColor: null,
disabledThumbColor: null,
thumbShape: null(),
overlayColor: null,
valueIndicatorColor: null,
valueIndicatorShape: null(),
showValueIndicator: null,
valueIndicatorTextStyle: TextStyle(
color: Color( 0xffffffff ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
),
tabBarTheme: TabBarTheme(
indicatorSize: TabBarIndicatorSize.tab,
labelColor: Color( 0xffffffff ),
unselectedLabelColor: Color( 0xb2ffffff ),
),
chipTheme: ChipThemeData(
backgroundColor: Color( 0x1f000000 ),
brightness: Brightness.light,
deleteIconColor: Color( 0xde000000 ),
disabledColor: Color( 0x0c000000 ),
labelPadding: EdgeInsets.only(top:0,bottom:0,left:8, right:8),
labelStyle: TextStyle(
color: Color( 0xde000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
padding: EdgeInsets.only(top:4,bottom:4,left:4, right:4),
secondaryLabelStyle: TextStyle(
color: Color( 0x3d000000 ),
fontSize: null,
fontWeight: FontWeight.w400,
fontStyle: FontStyle.normal,
),
secondarySelectedColor: Color( 0x3d2196f3 ),
selectedColor: Color( 0x3d000000 ),
shape: StadiumBorder( side: BorderSide(color: Color( 0xff000000 ), width: 0, style: BorderStyle.none, ) ),
),
dialogTheme: DialogTheme(
shape: RoundedRectangleBorder(
side: BorderSide(color: Color( 0xff000000 ), width: 0, style: BorderStyle.none, ),
borderRadius: BorderRadius.all(Radius.circular(0.0)),
)
),
);

Can you change flutter text theme?

If the theme is set in main.dart as
return MaterialApp(
title: 'MY APP',
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: 'Cabin',
textTheme: TextTheme(
headline1: TextStyle(
fontFamily: 'Raleway',
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 18,
),
subtitle1: TextStyle(
fontFamily: 'Raleway',
color: Colors.black54,
fontWeight: FontWeight.w600,
fontSize: 16,
),
),
),
and I'm using the theme as
Text('MY STRING',
style: Theme.of(context).textTheme.subtitle1),
How can I make 'MY STRING' be a different color then the subtitle1 theme color while keeping the other properties of theme data, such as font weight and family and size, etc.?
You can use de method copyWith(color: your_color) to change properties of a TextTheme.
Example:
Text('MY STRING',
style: Theme.of(context).textTheme.subtitle1
.copyWith(color: Colors.red),
)
Doc Reference: https://api.flutter.dev/flutter/material/TextTheme/copyWith.html

Overflow error in date picker in flutter?

I am using the date picker but it's showing a strange overflow text-overflow error.
I know the date picker uses the app Theme to style. But don't know which Theme property is used to style what in the dialogue box.
my Date picker:-
showDatePicker(
ontext: context,
initialDate: DateTime.now(),
firstDate: DateTime.now(),
astDate: DateTime.utc(2100, DateTime.now().month, DateTime.now().day),
);
my App Theme:-
ThemeData(
primaryColor: Color(0xffE6F5F1),
accentColor: Color(0xFF4EB799),
visualDensity: VisualDensity.adaptivePlatformDensity,
scaffoldBackgroundColor: Colors.white,
textTheme: TextTheme(
headline2: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 96,
letterSpacing: -1.5,
fontFamily: "Muli",
),
headline3: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 60,
letterSpacing: -0.5,
fontFamily: "Muli",
),
headline4: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 48,
letterSpacing: 0,
fontFamily: "Muli",
),
headline5: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 34,
letterSpacing: 0.25,
fontFamily: "Muli",
),
subtitle1: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 24,
letterSpacing: 0,
fontFamily: "Muli",
),
headline6: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 20,
letterSpacing: 0.15,
fontFamily: "Muli",
),
subtitle2: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 18,
letterSpacing: 0.15,
fontFamily: "Muli",
),
bodyText2: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16,
letterSpacing: 0.5,
fontFamily: "Muli",
),
bodyText1: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14,
letterSpacing: 0.25,
fontFamily: "Muli",
),
button: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 14,
letterSpacing: 1.25,
fontFamily: "Muli",
),
caption: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 12,
letterSpacing: 0.4,
fontFamily: "Muli",
),
overline: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 10,
letterSpacing: 1.5,
fontFamily: "Muli",
),
),
);
What is wrong here, which theme property to style what in Date picker in flutter?
In source code date_picker_dialog.dart
landscape mode use headline5
portrait mode use headline4
final TextStyle dateStyle = orientation == Orientation.landscape
? textTheme.headline5?.copyWith(color: dateColor)
: textTheme.headline4?.copyWith(color: dateColor);
...
final Widget header = DatePickerHeader(
helpText: widget.helpText ?? localizations.datePickerHelpText,
titleText: dateText,
titleStyle: dateStyle,
orientation: orientation,
isShort: orientation == Orientation.landscape,
icon: entryModeIcon,
iconTooltip: entryModeTooltip,
onIconPressed: _handleEntryModeToggle,
);
working demo
full code reduce headline4 font size
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primaryColor: Color(0xffE6F5F1),
accentColor: Color(0xFF4EB799),
visualDensity: VisualDensity.adaptivePlatformDensity,
scaffoldBackgroundColor: Colors.white,
textTheme: TextTheme(
headline2: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 96,
letterSpacing: -1.5,
fontFamily: "Muli",
),
headline3: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 60,
letterSpacing: -0.5,
fontFamily: "Muli",
),
headline4: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 30,
letterSpacing: 0,
fontFamily: "Muli",
),
headline5: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 34,
letterSpacing: 0.25,
fontFamily: "Muli",
),
subtitle1: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 24,
letterSpacing: 0,
fontFamily: "Muli",
),
headline6: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 20,
letterSpacing: 0.15,
fontFamily: "Muli",
),
subtitle2: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 18,
letterSpacing: 0.15,
fontFamily: "Muli",
),
bodyText2: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 16,
letterSpacing: 0.5,
fontFamily: "Muli",
),
bodyText1: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 14,
letterSpacing: 0.25,
fontFamily: "Muli",
),
button: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 14,
letterSpacing: 1.25,
fontFamily: "Muli",
),
caption: const TextStyle(
fontWeight: FontWeight.w400,
fontSize: 12,
letterSpacing: 0.4,
fontFamily: "Muli",
),
overline: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 10,
letterSpacing: 1.5,
fontFamily: "Muli",
),
),
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime.utc(2100, DateTime.now().month, DateTime.now().day),
);
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}