Best way to show conditional text in form bloc?
What is the best way to show conditional text widgets (read only, not input) in a form when using this library? I have a requirement based on selections made in the form, to show data, and other selection fields. So for the selection fields I've been using the onchange and adding or removing. However I'd like to do the add or remove a regular text widget. Any thoughts on the best solution for that? Thanks.
hello, this could be an option
CanShowFieldBlocBuilder(
fieldBloc: formBloc.conditionalField,
builder: (context, canShow) {
return Text('Conditional Label');
},
),
Ok, this is getting there.. I have it working with static text. Is there a way to pass in a variable so that the Text can show a dynamic message? I am attempting a booking screen, where the users selects a date and time, this is all working well and dynamically responding , however I then need to present some dynamic data from the response, in text form, along with new fields. Everything works except for displaying the dynamic text.
where does the dynamic text come from?
When the user changes the startTime it does a lookup and returns bookingInfo. I would like to integrate that into some text in a Text widget to display along with, as you can see some other fields. The conditionalField below is the one that I'm using that CanShowFieldBlocBuilder on..
startTime.onValueChanges(onData: (previous, current) async* {
print('current: $current');
final bookingInfo = await bookingsRepository.getSimAvail(
bookingDate.value, '14:00', int.parse(numberOfHours.value));
print('bookingInfo: ${bookingInfo}');
if (bookingInfo != null) {
print('adding NumberOfPlayers');
addFieldBlocs(fieldBlocs: [conditionalField, numberOfPlayers, players]);
} else {
removeFieldBlocs(fieldBlocs: [numberOfPlayers, players]);
}
});
- set the type of
ExtraDatain the field bloc, String or any Class this is used for you to add whatever you want to the state of field bloc
final textField = TextFieldBloc<BookingInfo>();
- update the object using
field.updateExtraData()
...
if (bookingInfo != null) {
textField.updateExtraData(bookingInfo);
}
...
- access to this object with a bloc builder
CanShowFieldBlocBuilder(
fieldBloc: formBloc.textField,
builder: (context, canShow) {
return BlocBuilder<TextFieldBloc<BookingInfo>, TextFieldBlocState<TextFieldBloc>>(
cubit: formBloc.textField,
builder: (context, state) {
return Text(state.extraData.someValue);
},
);
},
),
I would like to thank you for your assistance on this.. I now have this piece working and it's pretty slick...