Bloc: Complex dynamic field with bloc

Created on 22 Oct 2019  路  3Comments  路  Source: felangel/bloc

Is there any example of using bloc with Complex form? That means, If there is a form in a page, and have a action to add a lot of sub-form, and the sub-from have a lot of TextFormField. How could we make a bloc to such a page. I thought I need to make three bloc. One for the current page, one for sub form, and one for sub-sub-form.

For making more sense, How could we design a bloc for following structure?

Container(
    child: Column(
        children: _dyanmicForms() // could dynamic add more form in same page
    ),
)

---
_dynamicForms() {
   return Form(
        child: Column(
             children: <widget>[
               _aLotOfTextFieldForm() // could dynamic add more field to input
               _aDropdown()
             ]
        )
   )
}

Sorry for asking this kind of strange question, but I couldn't find an example about how could bloc handle dynamic fields. It's hard for me, when I encounter a lot of dynamic TextEditController, and I can't find a way to handle It. If I use the bloc as ComplexLoginState , It could look like:

@immutable
class ComplexLoginState {
  final List<bool> _textFormFieldValids;
}

And I need to handle List<TextEditController> somewhere else to ensure the two list is the same length, and same CRUD operation. That let me confuse about Bloc to handle complex page. However, Bloc is useful with simple page and your tutorial is awesome.

By the way, your page is 404 today, hope you could check It 馃槃

question

All 3 comments

1 . replace all your functions with stateless widgets

check : https://stackoverflow.com/q/53234825/4009642

2 . wrap BlocBuilder only around the widgets that actually use it

so if you dynamically add a text form field, wrap your BlocBuilder around it

@bigworld12 Did you mean one TextFormField with one Bloc? It sounds right, I'll give It a try. Thanks!

Thanks @bigworld12 for helping @Tokenyet 馃憤

Closing for now but @Tokenyet feel free to comment with additional questions and I'm happy to re-open this and continue the discussion 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shawnchan2014 picture shawnchan2014  路  3Comments

krusek picture krusek  路  3Comments

MahdiPishguy picture MahdiPishguy  路  3Comments

RobPFarley picture RobPFarley  路  3Comments

hivesey picture hivesey  路  3Comments