I have a Button:
This is just a simple button with a center aligned text. Now imagine I need to add a widget next to the text in horizontal axis!
Something like this:
SizedBox(
width: double.infinity,
height: 56,
child: TextButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
const Color(0XFF00966D),
),
foregroundColor: MaterialStateProperty.all<Color>(
const Color(0XFFFAFAFA),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
),
),
onPressed: () {
Navigator.popAndPushNamed(context, "signupPhoneVerification");
},
child: const Text('Sign Up'),
),
),
How can I do this?
4
Answers
Wrap
Text
widget with aRow
widget and add the Widget you want after theText
widget.Instead of
child: const Text('Sign Up')
you could useUse
TextButton
like below:wrap your button with
stack
. and feel free to position your widget on it anywhere you want, better than a row way which you will be aware of any overflow .There could be many ways to achieve this:-
With
SizedBox()
– Dividing the row’s children in 3 same-sized portions:With
MainAxisAlignment.center
– Addding a widget on the left to balance it:With
Stack
: