渲染Flutter TextFormBloc时出现问题

时间:2020-05-14 00:46:10

标签: forms flutter rendering flutter-layout

我在UI中使用TextFieldBlocBuilder。我已经对此进行了一段时间的故障排除,但无法弄清“为什么” textfieldbloc没有出现在我的应用中。我已经用简单的Text包围了它,并且出现了这两个文本字段,但是textfieldbloc没有。我附带了一段代码,非常感谢任何能告诉我原因或将我指向要研究的方向的人……我很沮丧。 (此外,我已经确认我在textfieldbloc中填充的字段实际上具有值。)

@override
Widget build(BuildContext context) {
 return Card(
     color: Colors.blue[100],
     margin: const EdgeInsets.all(8.0),
     child: Padding(
       padding: const EdgeInsets.all(8.0),
       child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
         Row(
           // Row 1
           mainAxisAlignment: MainAxisAlignment.spaceBetween,
           children: <Widget>[
             Padding(
               padding: const EdgeInsets.all(8.0),
               child: Text(
                 'Ingredient #${ingredientIndex + 1}',
                 style: TextStyle(fontSize: 20),
               ),
             ),
             IconButton(
               icon: Icon(Icons.delete),
               onPressed: onRemoveIngredient,
             ),
           ],
         ),
         // Ingredient Attributes
         new Column(
           mainAxisSize: MainAxisSize.min,
           children: [
             Card(
                 //color: Colors.grey[100],
                 color: Colors.purple,
                 child: Padding(
                     padding: const EdgeInsets.all(8.0),
                     child: Column(
                         mainAxisSize: MainAxisSize.min,
                         children: <Widget>[
                           Text("Yo"),
                           TextFieldBlocBuilder(
                             maxLength: 30,
                             maxLines: 1,
                             textInputAction: TextInputAction.next,
                             textFieldBloc:
                                ingredientField.ingredientName,
                             decoration: InputDecoration(
                               labelText: 'Ingredient Name',
                             ),
                           ),
                            Text("Yo-2"),
                         ]))),
           ],
         ),
       ]),
     ));
}
}

这是BlocBuilder代码:

                        // Ingredient Card Start
                        BlocBuilder<ListFieldBloc<IngredientFieldBloc>,
                            ListFieldBlocState<IngredientFieldBloc>>(
                          bloc: formBloc.ingredients,
                          builder: (context, state) {
                            if (state.fieldBlocs.isNotEmpty) {
                              return
                                  // Constrained Box Start
                                  ConstrainedBox(
                                      constraints: BoxConstraints(
                                          maxHeight: 800,
                                          minHeight: 56.0,
                                          maxWidth: 800),
                                      child:
                                          // Constrained Box End
                                          ListView.builder(
                                        shrinkWrap: true,
                                        physics:
                                            const NeverScrollableScrollPhysics(),
                                        itemCount: state.fieldBlocs.length,
                                        itemBuilder: (context, i) {
                                          return IngredientCard(
                                            ingredientIndex: i,
                                            ingredientField:
                                                state.fieldBlocs[i],
                                            onRemoveIngredient: () =>
                                                formBloc.removeIngredient(i),
                                          );
                                        },
                                      )

                                      );
                            } else {
                              logger.d("_RecipeUpdate:xxx - state.fieldBlocks is empty");
                            }
                            return Container();
                          },
                        ),

这是应用程序中为此小部件呈现的内容(我希望textFieldBloc出现在“ Yo”和Yo-2”之间):app screenshot

0 个答案:

没有答案