Flutter ElevatedButton shape - rectangle - flutter

This should be the easiest one ever.
I am coming back to flutter after years away as I am forced to update my old app. Everything has changed!
I am trying to make an ElevatedButton that is square. The default has slightly rounded edges that looks weird when I am making a button the width of the screen.
All I want to know is how I can make this button a square. That's it! No tricks!
ElevatedButton has:
ElevatedButton.styleFrom(
shape: ???,
),
But I can't find any information anywhere online what my options are for shape. Only a few examples on how to make it round or beveled or literally every other shape you can think of except for a simple rectangle :D

Try below code:
ElevatedButton, ButtonStyle, BorderRadius
ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
//borderRadius: BorderRadius.zero, //Rectangular border
),
),
onPressed: () {},
child: const Text(
'Submit',
),
),
Result->

Related

Is it possible to set default border radius in Theme in Flutter?

I am learning Theme and ThemeData for Flutter.
I can comfortable deal with colors, however I am missing a global BorderRadius setting.
How to make (via ThemeData) that all widgets will have BorderRadius 0 by default (sharp corners)?
Yes, that is possible. You can change the borderRadius for every button type. To do so, add the following lines to your ThemeData:
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
You can see that all of your TextButtons should now have a borderRadius of 8. This works for all other buttons accordingly.

Apply invert-like color filter to child with ColorFiltered widget

I want to invert the color of a certain child within a stack widget using ColorFiltered.
From:
To:
I had tried playing with the available filter mode but I cannot achieve such an effect yet, can someone tell me how to achieve the invert-like color filter effect?
ColorFiltered(
colorFilter: const ColorFilter.mode(
Colors.white,
BlendMode.difference,
),
child: Container(
color: Colors.white,
child: Text('Invert Me'),
),
),
Will do the trick, it will invert the color of its descendants, including photos, videos, or even text.

How to fill color in the icon in flutter

I am new in flutter. I am using multiple theme(i.e. dark mode) in the app. So, When we use icon in different theme, automatically take background color according to the theme. I want background color of theme but not inside the icon.
Example:
I am using youtube's icon in dark theme so look like below,
But i want to like below,
I am using
Icon(
FontAwesomeIcons.youtube,
color: Colors.red
)
So how to fill the color white in this icon ? (Or also you can suggest me to do that in proper as well as better way to implement)
(so, i can use white filled icon in every theme)
You can use a Stack to place a filled Container under your icon like so:
Stack(children: <Widget>[
Positioned.fill(
child: Container(
margin: EdgeInsets.all(5), // Modify this till it fills the color properly
color: Colors.white, // Color
),
),
Icon(
FontAwesomeIcons.youtube, // Icon
color: Colors.red,
),
),
])
Since its a container, you can also modify its shape in case there are random icon shapes that a normal square does not help in :P
I tried filling the icon play_circle_filled with green using this on DartPad and it gave me this:
I also faced the same issue. I think there could be a modification in Sidak's solution. Instead of using a container in the background, we could use the same Icon of the desired color in the background using the stack widget.
Stack(children: <Widget>[
Positioned.fill(
child: Container(
margin: EdgeInsets.all(5), // Modify this till it fills the color properly
color: Colors.white, // Color
),
),
Icon(
FontAwesomeIcons.youtube, // Icon
color: Colors.red,
),
),
])

Flutter: ClipRRect vs Container with BoxDecoration

I know that ClipRRect has additional options like custom clipper. But if I need just a simple border radius is there any performance difference? Which one is more recommended?
If your goal is to create a rounded border, you must use clippers only in the last situation, when containers may not help. For example, images can draw over rounded borders, so you have no other option unless clipping the image.
how about shape, shape vs cliprrect
RaisedButton(
onPressed: () {},
child: Text('Test'),
shape: RoundedRectangleBorder(
side: BorderSide.none,
borderRadius: BorderRadius.all(Radius.circular(50))
),
)

Click effect not smooth

I am having a problem with the smoothness of my app animation.
I have 20 buttons on this page. If I press any of the buttons, the click effect is not running smoothly. The frame rate is very low. Is there any problem with the code or it is a bug?
Thanks in advance.
Here is a slightly streamlined version of your button builder method that properly contains the ink effect in the rounded rectangle shape, but that should not impact performance. Performance-wise, there is nothing wrong with your code.
Widget buildMaterialButton() {
return Expanded(
child: RawMaterialButton(
fillColor: Colors.blueGrey,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40.0)),
onPressed: () {},
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Text("1"),
),
),
);
}