I try to fix the width size of my button but each time it takes all the available space in the width of the screen. I attach the code of the button :
ConstrainedBox(
constraints: BoxConstraints.tight(const Size(200, 35)),
child: ElevatedButton(
onPressed: () async {
types.Room room =
await FirebaseChatCore.instance.createRoom(user!);
if (!mounted) return;
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ChatPage(room: room),
),
);
},
child: Container(
color: Colors.blue,
child: const Text(
"Send Message",
),
),
),
),
I tried to change the container by SizedBox but the same error has occurred.
Thanks for your help,
3
Answers
You can resize your Elevated button with SizedBox like this:
You can wrap your ElevatedButton with SizedBox and then Further wrap it up with UnconstainedBox widget if the Button still doesn’t get the explicit size.
ElevatedButton
have style parameter that useElevatedButton.styleFrom
. In which we have three parameter for size.To change only the width, use
Size.fromWidth(100)
.