'FormBuilder radio buttons, value and image next to each other
I stumbled across this question of styling FormBuilderRadioGroup. I want to make a row for each option. In that row I want the value of the radio button and an image. See picture: https://imgur.com/a/v1qzA6X.
I tried to do this in the options property, but that property is expecting a list of <FormBuilderFieldOption>so I cannot return a row...
Code
FormBuilder(
autovalidateMode: AutovalidateMode.always,
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FormBuilderRadioGroup(
onChanged: (value) {
String paymentMethod = value.toString();
paymentViewModel.setPaymentMethod(paymentMethod);
print(paymentMethod);
},
initialValue: "mollie_wc_gateway_ideal",
decoration: const InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(horizontal: 0),
),
orientation: OptionsOrientation.vertical,
name: "paymentMethod",
options: paymentViewModel.paymentOptions!
.map((option) => FormBuilderFieldOption(
value: option.id,
child: Text(option.title),
))
.toList(growable: false)),
],
)),
The code above just displays 3 radio buttons with plain text. I really want an image of the payment method on the right side.
Solution 1:[1]
Maybe you should not use the package flutter_form_builder. Just use the built in Form in Flutter. Maybe that could help?
Solution 2:[2]
you can try this one :
options: paymentViewModel.paymentOptions!
.map((option) => FormBuilderFieldOption(
value: option.id,
child: Row(
children: [Text('option.title'),Image.network('URL')]
,mainAxisAlignment: MainAxisAlignment.spaceEvenly
),
))
.toList(growable: false)),
],
)),
Solution 3:[3]
Did you try like this?
.map((option) => FormBuilderFieldOption(
value: option.id,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children:[
Text(option.title),
Image widget,
],
),
)).toList(growable: false)),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Peta |
| Solution 2 | Anas Altarazi |
| Solution 3 | ViKi Vyas |
