Flutter TextButton onPrimary alternative - flutter

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)),
),

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

How can I style an elevated button?

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

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.

Remove or modify navigation drawer overlay shadow in Flutter

I created a Scaffold widget with appBar and drawer.
As I open the drawer, there is a shadow over the Scaffold's body widget. I'd like to either remove the shadow, make it not so "strong" or change the shade slightly.
I checked the docs and I didn't find any way to achieve this through public API.
Is there any way to remove the drawer menu's "drop shadow" on the body?
The elevation option is something different, even if I set it to 0, the overlay shadow on top of the body is still present.
This issue's description's screenshots might help clarify what I want.
If you want to get rid of the shadow over the Scaffold body then you have to change the Scaffold's drawerScrimColor's value to Colors.transparent.
Have you tried setting the drawer's elevation to elevation: 0.0?
check this
drawerTheme:
DrawerThemeData(scrimColor: Colors.transparent, elevation: 0.5),

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