Here’s the code I’m using for this answer button:
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class AnswerButton extends StatelessWidget {
const AnswerButton(
{super.key, required this.answerText, required this.onTap});
final String answerText;
final void Function() onTap;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: ElevatedButton(
onPressed: onTap,
style: ElevatedButton.styleFrom(
fixedSize: const Size.fromHeight(20),
backgroundColor: Colors.white,
foregroundColor: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(12),
),
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
),
child: Text(answerText, style: GoogleFonts.rubik(fontSize: 15)),
),
);
}
}
Tried several things like Limited Box or ellipsis which isn’t working either.
2
Answers
Use
FittedBox
for wrappingText
and you need container to determine the size ofElevatedButton
because i tried withoutContainer
,FittedBox
not working as expected. The code:the result:
Remove
fixedSize
fromElevatedButton.styleFrom
.Additionally, if you want all text to be centered add this to the
Text
widget: