AppBar text color in Flutter - flutter

When I’m setting primarySwatch: Colors.blue, I’m getting white texts in AppBar.
However, when I’m switching to primarySwatch: Colors.cyan, texts are black.
I guess, Google does some kind of magic and automatically adjusts it.
How to globally edit theme to show always white texts in AppBar (for title and tabs).

You can use this code and see if that works
appBar: AppBar(
title: Text(
'History',
style: TextStyle(color: Color(0xffffffaa)),
),
),

Related

Change back icon for whole app at one not by doing manually on individual on each screens

i want to change the back button icon for whole app not by changing it individually on screens i am unable to find out any placeholder to change the icon in app bar theme
there is no option for icon in appBarTheme
appBarTheme: AppBarTheme(
elevation: 0,
systemOverlayStyle: SystemUiOverlayStyle(statusBarBrightness: Brightness.light),
titleTextStyle: Theme.of(context).textTheme.headline6,
color: Colors.transparent,
iconTheme: IconThemeData(color: dark3)),
Do like this.
If you are using Scaffold then under Scaffold in the appBar params there is one param called leading Icon. Change that and you'll get your desired icon as a Back Icon.
Scaffold(
appbar:AppBar(
leading:
//<put that type of icons/widget you want to use >
),
body:
//...
)
make a custom appbar like this and use this wherever you need.
AppBar customAppBar()=>AppBar(
leading: //<put that type of icons/widget you want to use >
//other params as per your requirement
);

Best practice to propagate theme through flutter screens

I've made a basic theme for my app and set it in the MaterialApp widget
ThemeData(
primaryColor: Colors.black,
backgroundColor: Colors.grey.shade50,
scaffoldBackgroundColor: Colors.grey.shade50,
buttonColor: Colors.purple,
);
but it seems the theme is not being updated on MaterialAppshome
home: LoginScreen()
. the button nor the background (supposed to be black and gray) aint updating...
What is the correct way of doing this?
As per the docs:
Using a Theme
Now that you’ve defined a theme, use it within the widgets’ build() methods by using the Theme.of(context) method.
The Theme.of(context) method looks up the widget tree and returns the nearest Theme in the tree. If you have a standalone Theme defined above your widget, that’s returned. If not, the app’s theme is returned.
In fact, the FloatingActionButton uses this technique to find the accentColor.
Container(
color: Theme.of(context).accentColor,
child: Text(
'Text with a background color',
style: Theme.of(context).textTheme.headline6,
),
),

ExpansionTile Title color changes on expansion

ExpansionTile(
title: Text('test'),
children: [Text('test expanded')],
),
In this simple test, when I click on the title to expand the widget, the original title text turns from black to grey. I'm not sure if this is a Theme issue (I tried changing every grey color to something bright) or is something that I can manage through ExpansionTile (don't see it in the hover menu).
I did find that I could explicitly state the text color should be black and then it stays constant. However, in my real world use case for this tile I have several Text widgets and don't want to have to color each one.
Any ideas on how to address this in one shot?
It is an animated color between accentColor & subtitle1 color. So, you can override theme like this.
Theme(
data: ThemeData(
accentColor: Colors.black,
textTheme: TextTheme(
subtitle1: TextStyle(color: Colors.black),
),
),
child: ExpansionTile(
title: Text('test'),
children: [Text('test expanded')],
),
),

Flutter, AppBar Color change

Is there a way that the AppBars color can be changed through a gradient and opacity as an example? From something lighter to something darker to see the icons above the phone clearer.
Fixed.
appBar: AppBar(
brightness: Brightness.light,
backgroundColor: Colors.white,
elevation: 0.0,
if I understand correctly you want to change the appbar color with one of these methods :
1) change AppBar color only
witch will affect the background of appbar only
appBar: AppBar(
backgroundColor: PrimaryColor,
),
1) change primary App color swatch :
witch will change all the colors of buttons , etc to a certain color including appbar
MaterialApp(
primaryColor: Colors.red,
)
2) Switch to dark mode :
witch will invert the colors of all app to dark mode
MaterialApp(
title: title,
theme: ThemeData.dark(),
)

How to set textStyle of a Cupertino app in flutter

I have a CupertinoApp and I would like to apply a custom TextStyle to all the screen/object of my app. For example I would lie to set a font family to all Text widget & Dialog widget and use that font across all my app. I was hoping to set it once in CupertinoThemeData or CupertinoTextThemeData but so far I did not have joy.
Note: I am able to set style for each Text however I would like to set it once for all
I've just run into this at the moment.
All I'm trying to do is colour text white, with general black backgrounds across the app (not font work).
The following has brought me some success:
return CupertinoApp(
theme: new CupertinoThemeData(
brightness: Brightness.dark,
primaryColor: CupertinoColors.dark,
barBackgroundColor: CupertinoColors.black,
scaffoldBackgroundColor: CupertinoColors.black,
textTheme: new CupertinoTextThemeData(
primaryColor: CupertinoColors.white,
brightness: Brightness.light,
textStyle: TextStyle(color: CupertinoColors.white),
// ... here I actually utilised all possible parameters in the constructor
// as you can see in the link underneath
),
),
// ...
)
Ref: CupertinoTextThemeData Constructor
I think you could extend my TextStyle(color: CupertinoColors.white) to apply fonts too. I intend to extract the TextStyle and ...ThemeData into separate classes to create a single place to edit them.
Hopefully this advances your position
Use this example of theme in your CupertinoApp .
theme: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
textStyle: TextStyle(
fontSize: 14,
fontStyle: FontStyle.italic,
backgroundColor: CupertinoColors.black)),
),
Reminder : For the colors, use a CupertinoColor instead of a simple
Color.
My code is here