How To Change Flutter Raised Button Elevation

Flutter raised button elevation

In this post, we will understand what Flutter raised button elevation is and how to change it using a proper Flutter easy example. A step by step explanation will also be provided so you can have a better practical understanding of how to use and change Flutter raised button elevation. So let’s get right into it.

What is Flutter Raised Button Elevation?

Flutter raised button elevation is used to specify that how much the shadow of the Flutter raised button should spread. The more it spread will make the button look more elevated or you can say at higher position. The Flutter raised button has a default shadow with some elevation. Let’s now understand it using a practical Flutter example.

Default Flutter Raised Button Elevation

To see the default Flutter raised button elevation, we have to define a simple Flutter raised button, we have also passed a Flutter text widget just to make the Flutter raised button looks good. See the below code:

 RaisedButton(
             onPressed: () {},
             child: Text('Default Raised Button Elevation'),
                  )
Flutter raised button default elevation
The default Flutter raised button elevation can se seen in the above image. The shadow is being emitted by the Flutter raised button which makes it look elevated. Now that we have seen the default Flutter raised button elevation, let’s now see how to change that elevation.

Change Flutter Raised Button Elevation

In order to change the elevation, we have to use the elevation constructor of the Flutter raised button widget class. The elevation constructor takes a double(decimal value but you can also pass integer value, it will convert it automatically), we have passed it a zero value for demonstration. See the below code:

 RaisedButton(
             onPressed: () {},
                    elevation: 0,
                    child: Text('Custom Raised Button Elevation'),
                  )
Flutter raised button no elevation
As you can see in the above image, the raised button is no longer spreading any shadow, the reason is that we have set the elevation to zero as seen in the above code.
Now let’s give the elevation constructor a larger value. We have given it a value of 15 to demonstrate what the elevation will look. See the below code:
 RaisedButton(
            onPressed: () {},
                elevation: 15,
                    child: Text('Custom Raised Button Elevation'),
                  )
Flutter raised button elevation
In the above image, we can see that the Flutter raised button is now well elevated.
You now have a complete practical understanding of how to use and change the Flutter raised button elevation. You can give it larger or less value to see what elevation works for you. If you still have any queries in mind regarding the customization of Flutter raised button elevation then do let me know in the comment section. I would love to clear all your queries.
The complete source code for the customized Flutter raised button elevation is available in the next section.

Flutter Raised Button Elevation Source Code

Flutter raised button elevation

import 'package:flutter/material.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Homepage(),
    );
  }
}
class Homepage extends StatefulWidget {
  @override
  State<Homepage> createState() => _HomepageState();
}
class _HomepageState extends State<Homepage> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
      body: Center(
          child: Padding(
              padding: EdgeInsets.symmetric(horizontal: 40),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  RaisedButton(
                    onPressed: () {},
                    elevation: 15,
                    child: Text('Custom Raised Button Elevation'),
                  )
                ],
              ))),
    ));
  }
}

Conclusion

In conclusion, you have now practical knowledge of what Flutter raised button elevation is and how to use it in Flutter apps. I seriously appreciate you taking the time to read this article and would love to have your feedback on it. I highly recommend other posts on Flutter widgets, Flutter app development, Flutter animations, Flutter books, Flutter templates with source code and others. Links to some of them can be found listed below. Others can be found using the search box or the menu navigation bar. Thanks for reading this post.

Leave a Comment

Your email address will not be published. Required fields are marked *