How can I style an elevated button? - flutter

I want to give a background color for an elevated button in my flutter mini app. I tried using the buttonStyle attribute but I don't know what MaterialStateProperty is.

You can use one of these two methods. And for tour question you can use the first option.
style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Colors.green)),
or
style: ElevatedButton.styleFrom(primary: Colors.amber),

You use the style from property

Related

Flutter - Change color of selected text in a Textfield

I have a Searchbar and due to my app theming, the text inside becomes hard to read when its selected. I would like to know if there is a way to set a different text color when it's selected.
Thanks in advance!
Flutter does not support changing the selected text color via the theme declaration in the main widget, only can change background color. You must use the SelectableText in each input style property, like as:
SelectableText(
'Example text',
style: TextStyle(color: Colors.red), // Yout text color on selected
)
Reference: https://github.com/flutter/flutter/issues/99231

Flutter TextButton onPrimary alternative

I just started with flutter and got a question regarding the TextButton(). With an ElevatedButton I can use .styleFrom with the onPrimary property to change the color of shadowy animation which comes when I click the button.
But for my Navbar I need the TextButton, it has this effect aswell but onPrimary doesnt work there so I cannot change the shadow to another color than the default black, how can you change this style for a TextButton?
Thanks in advance
The only solution I came up with was changing
style: TextButton.styleFrom()
with ButtonStyle - you can use overlayColor to change the shadow when you press it:
style: ButtonStyle(
overlayColor: MaterialStateProperty.all<Color>(Color(0x00FFFFFF)),
),

Flutter when is SF Pro Display or SF Pro Text used and how to assign them to a Text widget?

I use the following two Text widgets in my app:
Text('12,23123,123.123 asdASD',
style: TextStyle(
fontFamily: '.SF UI Text',
)),
Text('12,23123,123.123 asdASD',
style: TextStyle(
fontFamily: '.SF UI Display',
))
However, both are displayed with the same fontFamily.
The iOS typography docs say the following:
For SF, use Text for text that’s smaller than 20 points; use Display for text that’s 20 points or larger.
https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/typography/
How can I apply the different front families to my Text widgets?
The related GitHub issue to this question is currently under review by the Flutter Engineers and it seems that it is still in progress atm. Another related issue linked to this is this GitHub post, as mentioned by the Flutter team, the issue is yet to be identified.

hoverColor property of the Raised button class in Flutter, doesn't change?

Edit: I am using the IOS simulator, the following issue may not be persistent across all platforms.
I am under the impression that when creating a RaisedButton, it is possible to change the color of the button when the cursor hovers over the button.
However this does not appear to be the case.
// Create button
RaisedButton(
onPressed: () {},
color: Colors.redButtonBackgroundColo
textColor: Colors.white,
disabledColor: Colors.disabledRedButtonBackgroundColor,
disabledTextColor: Colors.white,
disabledElevation: 4,
elevation: 4,
hoverColor: Colors.redHoveredOverButtonColor, //<--- Here is where I would like to change the button color (to a slightly lighter shade.)
padding: const EdgeInsets.all(14.0),
),
Thanks in advance for any help you may provide.
Since the question is not very clear I am going to assume a few things.
First, you are running the app on flutter desktop or web.
In that case, the code should work perfectly fine.
If you are trying it on mobile, then there is no hover action on mobile, that's why the button would not change its color.
If you want to change the color on tap, then you can wrap the RaisedButton with a GestureDetector and use the onTap or onPanDown callback to manually change the color of the button.

How to call the icon theme for an icon

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