I am trying to change the size of a custom Button in my app but the size (width) stays the same no matter what I do
My code can be found here:
import 'package:flutter/material.dart';
class CustomAppButton extends StatelessWidget {
final VoidCallback onPressed;
final String title;
final double? height;
final double? width;
const CustomAppButton({
required this.onPressed,
required this.title,
this.height = 64,
this.width = 284,
super.key,
});
@override
Widget build(BuildContext context) {
return SizedBox(
width: width, // Force button to have this width
height: height, // Force button to have height
child: ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
child: Text(
title,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
);
}
}
How do I fix this and get the button to be that size?
2
Answers
you just need to make sure that the button respects the width and height you’re passing. You can do that by adding the minimumSize in the button’s style.
Basically, the minimumSize inside ElevatedButton.styleFrom() makes sure the button will have the width and height you want. This should fix your problem!
Wrap Elevated button with FractionallySizedBox Widget..