I have some ListTile widgets around my app, and all of them have an icon.
From here I see that I need to override my ListTile with
ListTileTheme(
iconColor: Colors.blue,
child: ..
)
since the ListTile.iconColor is gray by default and doesn't fallback to ThemeData.iconTheme.iconColor.
I wonder if there is a way to specify the list tile theme in ThemeData, so I don't have to create a new widget just for that.
For now, there isn't, but this feature may arrive in the next flutter release: https://github.com/flutter/flutter/issues/31247
Related
Many flutter widgets forces their child to inherit their style, like:
ElevatedButton(
child: Text("Click Me."),
onPressed: (){},
);
this ElevatedButton() will force its Text() child to inherit a specific text color, weight and so on...
My question is how to make a widget that forces its child to inherit a style from it, and Thank you ^^.
I tried using Theme widget but it's useless.
as pskink mentioned in the comments DefaultTextStyle worked well.
Apologies if this question doesn't belong here but some flutter design choices seem unintuitive to me and if you all could help me in understanding why it's done like this, I feel I would have a better grasp of this framework.
Also, I come from a webdev background, therefore CSS type styling makes sense to me so that could be another reason why this type of styling seems so different.
I haven't done a lot of flutter but from my limited experience I have the following questions:
(I realize that some of it may not be optimal and hence the reasons for my confusion might be me just doing it incorrectly, in which case please do correct me)
This is the code I wrote for changing the background color of a button
TextButton(
child: Text('Example'),
onPressed: onPressedFunction,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.SomeMaterialColor)
)
)
or alternatively
TextButton(
child: Text('Example'),
onPressed: onPressedFunction,
style: TextButton.styleFrom(backgroundColor: Colors.SomeMaterialColor),
)
Q1 Why do I have to specify that the style will be of type ButtonStyle(....), any style that goes into the button class should be of type ButtonStyle right?
Q2 The reason why setting backgroundColor isn't as straightforward as backgroundColor: CustomColor is because "backgroundColor isn't Colortype, so you can't use Colors.YourColor" , but why not? what advantage do you get by not making it ColorType
When changing the theme of the app, this is the code that I wrote
theme: ThemeData(
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.red,
).copyWith(
secondary: Colors.purple,
),
),
Q3. Using fromSwatch and copyWith seems convoluted, why isn't it something as simple as
ThemeData(
colorScheme: ColorsSchemeClass(
primarySwatch: Colors.red,
secondaryColor: Colors.purple,
),
)
I am sure there are excellent reasons for this type of design but I can't seem to understand them, therefore any help would be greatly appreciated.
First of all It's all depending on what is called Material Design by Google. It has certain guidelines that must be followed to achieve maximum Flutter theming advantage.
Q1: Dart is hard-type language in general. And the use cases is different form widget to another, with some similarities. for example Button style has on hover color or splash color. while Text doesn't need this property. But both of them has foreground color.
Q2: As I mentioned before, Material Design is essential for the Widget that flutter provide. you can make your custom widget the can take Colors directly but I would not recommend this approach.
Q3:In Material Design concept, There is two main type of colors, Primary and accent colors, That's makes Flutter deal with Color Swatch. For your example First create red color swatch and copy it's property with changing the secondary color to purple.
For more information with Material Design in general read this
link
How to implement it in flutter read this article
I'm making a Welcome Screen which has two TextButtons each wrapped in a Container.
one for Creating an account and another for logging in
(both of them have some shadow below them )
I managed to make both containers in flutter but I found out that the background color of the application is not pure white (#FFFFFF) which mean if I set the color of the login container to Colors.white it won't look like the background color of the app like above picture.
So I need a way to set the color of the login container to the same color as the application.
let's avoid hard coding I don't want to determine the background color with an external tool and set it to the button.
I was thinking of taking same color as parent or something like that but I don't know if that exists.
main.dart
WelcomeScreen.dart
The scaffold background color is Grey[50]. You can set background color on scaffold like
Scaffold(
backgroundColor: Colors.white,
Or for app
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: Theme.of(context).copyWith(
scaffoldBackgroundColor: Colors.white,
),
More about Theme.
I am using showCaseView package and when I'm highlighting widgets, cupertinoTabScaffold is also highlighted. ShowCaseWidget wrapping MaterialApp widget so TabScaffold and all other widgets wrapped by ShowCase package. Has anyone encountered this, how to solve this issue?
I changed the color of CupertinoTabScaffold depending on whether "showCaseView" is active now, or not:
tabBar: CustomCupertinoTabBar(
backgroundColor:
Provider.of<NotifyShowcaseState>(context).isShowcaseActive //I've created ChangeNotifier class for updating state
? const Color(0x99BDBDBD) //dimmed grey if showCase is active
: null, //default white color, if showCase is inActive
....
),
In flutter the MaterialApp widget has a theme property where you can set fonts, background colors etc... When I need a text theme for example, using the style property, I can set the theme with Theme.of(context).textTheme.title) . How would I do similar with setting the theme for icons. Icons doesn't have a style property.
You can use the IconTheme class.
new IconTheme(
data: new IconThemeData(
color: Colors.blue),
child: new Icon(Icons.add),
),
Hope it might help.
Try replacing the icons you want to style with IconButton widget which has color: property, but you should disable it to hide the effect of user clicks , or you can set the highlighting color to Colors.transparent