0

I want to create a rounded elevated button that changes color when pressed. So far I've used ButtonStyle() to change the color, using the code:

style: ButtonStyle(
                   backgroundColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) { 
       if (states.contains(MaterialState.pressed)) {
            return Colors.black;}
       return Colors.red;}))

This changes the color from red to black when touched. But I cant find a way to resize the button and create a rounded edges. I know how to do it with ElevatedButton.styleForm(), but with styleForm() I dont know how to make it change color when touched. Is there any other way I can do it with styleForm, or fuse both styles in one code?

1 Answer 1

1

using style property you can create your own shape.

 SizedBox(
                    height: 50,
                    child: ElevatedButton(
                        style: ButtonStyle(
                            shape: MaterialStateProperty.all<
                                    RoundedRectangleBorder>(
                                RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(18.0),
                                    side: BorderSide(color: Colors.red)))),
                        onPressed: () {
                          Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) => SignUp()));
                        },
                        child: const Text("Sign up here")),
                  ),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.