How To Change Flutter RaisedButton Width

flutter raisedbutton width

In this article, we will discuss how to change Flutter RaisedButton width and implement it using proper Flutter example so you have better idea of how to change and customize Flutter RaisedButton width.

What is Flutter RaisedButton Width?

Flutter RaisedButton width, as the name suggests, it is the horizontal space that he Flutter RaisedButton will cover. In this post we will see how we can increase or decrease the Flutter RaisedButton width. So let’s not waste anymore time and start implementing the customization of Flutter RaisedButton width using an easy Flutter example.

Default Flutter RaisedButton Width

To see the default Flutter RaisedButton width, we have to define a simple Flutter RaisedButton. We also have to use the onPressed constructor as it is required constructor. See the below code:

RaisedButton(
         onPressed: () {})
flutter raised button default width

As you can see in the above image, we have a raised button with a greyish background and we haven’t specified any child here here which is usually a Flutter text widget which shows the purpose of the raised button like login, singup or click here etc. We haven’t specified anything to show the default Flutter RaisedButton width.

Let’s now give it a Flutter text widget using the child constructor of the Flutter RaisedButton widget then we will implement the customization of Flutter RaisedButton width. See the below code:

 RaisedButton(
            onPressed: () {},
                child: Text('Click here'),
                  )
flutter raisedbutton
As you can see in the above image, we now have a text as well in our raised button.

Change Flutter RaisedButton Width

To change the width of Flutter RaisedButton, we have to use the padding constructor of the Flutter RaisedButton widget class. We have passed edge in sets symmetric and have passed a larger integer value to its horizontal constructor, as it takes a double value but passing it int will also work. See the below code:

RaisedButton(
           onPressed: () {},
                    padding: EdgeInsets.symmetric(horizontal: 80),
                    child: Text('Click here'),
                  )
Flutter RaisedButton width
As you can see in the above image that the Flutter RaisedButton width is changed and its much wider than the default width of Flutter RaisedRutton. You can make the value 0 and see that the width will decrease.
So by using the padding constructor, we can change the Flutter RaisedButton width. Hope you now have a clear practical knowledge regarding the customization of Flutter RaisedButton width. If you still face any problems regarding the customization of Flutter RaisedButton width then do let me know in the comment section. I would love to answer them.
As a treat, I have prepared a beautiful Flutter RaisedButton design for you in which Flutter RaisedButton width customization is also included. The complete source code can be found in the below section.

Custom Flutter RaisedButton Design Source Code

flutter raisedbutton width

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: () {},
                    padding:
                        EdgeInsets.symmetric(horizontal: 100, vertical: 20),
                    elevation: 10,
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(50)
                          .copyWith(bottomRight: Radius.circular(0)),
                    ),
                    color: Colors.blue,
                    child: Text(
                      'Click here',
                      style: TextStyle(color: Colors.white, fontSize: 16),
                    ),
                  )
                ],
              ))),
    ));
  }
}

Conclusion

In conclusion, hope you have a practical understanding of how to customize Flutter RaisedButton width and now it would be easy for you to use it in your Flutter projects. I would love to receive your valuable feedback on this post. I would also want you to visit my other posts on Flutter widgets, Flutter app development, Flutter animations, Flutter templates with free source code, and many more. Thanks for reading this post.

2 thoughts on “How To Change Flutter RaisedButton Width”

Leave a Comment

Your email address will not be published.