Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Fields from restful call #310

Open
bobosette opened this issue Jun 6, 2022 · 11 comments
Open

Get Fields from restful call #310

bobosette opened this issue Jun 6, 2022 · 11 comments

Comments

@bobosette
Copy link

Hi everybody. I need to implement a questionnaire inside my app and I get questions and answers from a restful call, so when I initialize fields I don't know exactly how many they will be and their type, but i will get these informations when i will make the call inside the onLoading() method

`

@OverRide
void onLoading() async {
try {
await Future.delayed(Duration(milliseconds: 1500));

 final questionnaire = await http.get(Uri.parse('https://myUrl.com'));

 need to build the form

  emitLoaded();
} catch (e) {
 

  emitLoadFailed();
}

}

`
How can I dinamically add fields to my FormBloc directly from the onLoading() method?

@aaassseee
Copy link
Contributor

@bobosette It seems the scope is too large. Would you like to share a sample JSON with what questionnaire will return?
It that only simple text field or with complex multiple selection form?

@bobosette
Copy link
Author

There should be only SelelecFieldBox

@aaassseee
Copy link
Contributor

@bobosette It is hard to do example if you don't provide any runnable code. Lacking with information I can only provide a rough idea to help you. Lets say we have a JSON list with object contain type and options, you can generate the field blocs by lopping the object list and create list of field blocs. After constructing the field bloc you can add the list of field bloc by addFieldBlocs function before emitLoaded().

@bobosette
Copy link
Author

bobosette commented Jun 6, 2022 via email

@aaassseee
Copy link
Contributor

@bobosette Sure, If you can give more information. I can give you a much more detail suggestion.

@bobosette
Copy link
Author

bobosette commented Jun 6, 2022 via email

@bobosette
Copy link
Author

Hi @aaassseee . I declared a
ListFieldBloc<SelectFieldBloc<QuestionnaireAnswerOption, Object>, dynamic>();
and then I tried with addFieldBlocs() inside onLoading(). It works great.
Thank you

@aaassseee
Copy link
Contributor

@bobosette Happy to help.

@bobosette
Copy link
Author

@aaassseee I have another question for you: What if I should have different FieldBloc inside my list (SelectFieldBloc, TextFieldBloc, etc....)?? Is it possible to declared a ListFieldBloc<dynamic, dynamic>() or I don't something similar?
It would be great to create a dynamic form.

@aaassseee
Copy link
Contributor

@bobosette dynamic is not the best options if there is a base type. For the field bloc except ListFieldBloc and GroupFieldBloc you can use SingleFieldBloc as their base type. If you include ListFieldBloc and GroupFieldBloc in your list of bloc, you can use FieldBloc as your base type.

@bobosette
Copy link
Author

I'll try with SingleFieldBloc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants