primarySwatch isn't setting primaryColor - flutter

I have read that primaryColor is a Color, primarySwatch is MaterialColor, which includes various set of a Color.
first, according to my flutter class, I set Theme like this
primarySwatch: Colors.pink,
accentColor: Colors.amber,
and when I set splashColor of InkWell, it worked.
splashColor: Theme.of(context).primaryColor,
but the VsCode suggest me a better way, and automatically migrated Theme like this
colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.pink)
.copyWith(secondary: Colors.amber),
But the new way does not changes primaryColor of splashColor, I checked it Through By print the Color, but the Color was 0xff2196f3, which is default I think(close to blue).
so Why the new way does not set primaryColor?

in new way, you should use it like this:
splashColor: Theme.of(context).colorScheme.primary,

Related

How to make `FloatingActionButton`s, `TextButton`s and `IconButton`s look the same in means of size, shape and color, using a theme in Flutter?

I want that the FloatingActionButtons, TextButtons and IconButtons will be visually consistent, thus look the same in means of size, shape and color, using a theme in Flutter. how can I achieve that?
For defining a theme, MaterialApp has a property named theme. There you have to provide the instance of ThemeData.
MaterialApp(
title: title,
theme: ThemeData(
brightness: Brightness.light,
)
);
For "FloatingActionButton", "IconButton" and "TextButton" to look like same you have to define the theme (all the properties which you want to be consistent) for all of them such as.
For IconButton
iconTheme: IconThemeData(
color: Colors.red,
),
For FloatingActionButton
floatingActionButtonTheme: FloatingActionButtonThemeData(
foregroundColor: Colors.red,
),
For TextButton
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: Colors.red,
),
),
My Suggestion:
Use the primarySwatch property for the consistent color scheme.
primarySwatch: Colors.red;

How to Modify FlutterFire UI Accent Colour

I've been struggling with attempting to modify the accent colour in FlutterFire UI.
Namely, I'd like to change the blue accent colour here to a different material colour, such as purple. I've messed around with the app theming to no avail, as none of the ThemeData parameters seem to influence this colour so far. I was wondering if this was possible? Thanks!
accent color is deprecated so now u can user Colorscheme instead like this
MaterialApp(
theme: ThemeData(
primarySwatch: Colors.orange,
colorScheme: ColorScheme.fromSwatch(accentColor: Colors.green),
),
home: NextScreen(),
);
You can use this in theme data
theme: ThemeData(
outlinedButtonTheme: OutlinedButtonThemeData(
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsets>(
const EdgeInsets.all(24),
),
backgroundColor: MaterialStateProperty.all<Color>(Colors.purple),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
),
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
foregroundColor:
MaterialStateProperty.all<Color>(Colors.purple)
)
)
),
I ended up finding the answer to my own question. Turns out the theming is part of the colour scheme property, and I ended up defining the following:
colorScheme: ColorScheme.fromSwatch().copyWith(
primary: Colors.deepPurpleAccent
)
This set them all to deepPurpleAccent!

How to set the overscroll from ThemeData

I have tried to change accentColor, colorScheme, primaryColor, secondaryColor, but none could change the overscroll color it still blue.
In a MaterialApp, the edge glow color is the overall theme's ColorScheme.secondary color.
GlowingOverscrollIndicator Docs
ThemeData Docs
Update theme in MaterialApp in main.dart like this:
theme: ThemeData(
primarySwatch: Colors.purple,
buttonTheme: ButtonThemeData(
buttonColor: Colors.purple,
textTheme: ButtonTextTheme.primary,
)
),

Can't set different colors for text in AppBar and text in Scaffold using ThemeData

In my MaterialApp widget, I'm using the theme property to set the universal theme for my app. I want to set a blue color for the text in the AppBar, and red color for text in the Scaffold body. But using textTheme in ThemeData, only the Scaffold's text has the intended color, not the AppBar text.
This is the code for the theme I'm using in MaterialApp:
theme: ThemeData(
primaryColor: Color(0xFF0A0E21), //a navy bluish color
scaffoldBackgroundColor: Color(0xFF0A0E21),
accentColor: Colors.purple,
textTheme: TextTheme(
headline6: TextStyle(
color: Colors.blue
),
bodyText2: TextStyle(
color: Colors.red
)
)
The AppBar text remains white, but text in the body of the app (in the Scaffold I'm using) changes to red. I'm not setting different colors anywhere else.
you have to use appBarTheme on themeData
ThemeData(
scaffoldBackgroundColor: Color(0xFF0A0E21),,
appBarTheme: AppBarTheme(
color: Colors.blue,
),

Change color of RaisedButton from theme not working

I tried changing the color of all my RaisedButtons from the themeData but it refused to work. All other properties, such as fontSize and fontWeight changed successfully. The color of the text only changes from black to white when the brightness property of themeData is changed to Brightness.dark.
Is there a way I can solve this issue? What could I be doing wrong?
Here is my sample code:
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primaryColor: Color(0XFF212845),
scaffoldBackgroundColor: Color(0XFF212845),
primarySwatch: Colors.yellow,
buttonColor: Color(0XFFF8D320),
textTheme: TextTheme(
button: TextStyle(
color: Colors.green, // This is not working.
fontSize: 30.0,
fontWeight: FontWeight.bold
)
)
),
home:MenuPage(),
);
For other people coming to this question, one reason that a button may not change colors is that it is disabled, which happens when you don't have the onPressed method set.
RaisedButton(
color: Theme.of(context).accentColor,
onPressed: () {}, // <-- need to add this
child: Text(...),
),
if you are giving a color to the color property and it doesn't show ,then probably you haven't implemented the onPressed property, because in this state the button will show it's disabled color , which is no color at all.
set it like this:
onPressed: () {},
giving it an anonymous function like that while not implementing anythig ( or something if you wish) will give it color
Add buttonTheme and accentColor to your ThemeData , like this:
ThemeData(
primaryColor: Color(0XFF212845),
scaffoldBackgroundColor: Color(0XFF212845),
primarySwatch: Colors.yellow,
buttonColor: Color(0XFFF8D320),
buttonTheme: ButtonThemeData(textTheme: ButtonTextTheme.accent),
accentColor: Colors.green,
Even though primarySwatch might have been added, you still need to add buttonColor to add the color to the buttons, like this:
child: MaterialApp(
home: Wrapper(),
theme: ThemeData(
primarySwatch: Colors.blue,
buttonColor: Colors.blue // this is needed
),
),
primarySwatch - used to configure default values for several fields,
including: primaryColor, primaryColorBrightness, primaryColorLight,
primaryColorDark, toggleableActiveColor, accentColor, colorScheme,
secondaryHeaderColor, textSelectionColor, backgroundColor, and
buttonColor.
Also, make sure onPressed in your RaisedButton is set:
onPressed: () {},
Make sure you haven't customize the RaisedButton() itself, else it will override the ThemeData. If you have customized color property in RaisedButton it will override the properties set in ThemeData.
I believe the correct way is to declare a buttonColor property in your ThemeData Widget.
MaterialApp(
theme: ThemeData(
fontFamily: 'Pirata',
primaryColor: Color.fromRGBO(71, 86, 87, 1),
accentColor: Color.fromRGBO(71, 86, 87, 1),
buttonColor: Color.fromRGBO(238, 238, 238, 1),
),
home: App()))