尝试在我的程序中运行一个简单的小部件,但收到"body_might_complete_normally"错误。我该如何纠正此问题?


// Build the whole list of todo items
Widget _buildTodoList() {
return new ListView.builder(
itemBuilder: (context, index) {
// itemBuilder will be automatically be called as many times as it takes for the
// list to fill up its available space, which is most likely more than the
// number of todo items we have. So, we need to check the index is OK.
if (index < _todoItems.length) {
return _buildTodoItem(_todoItems[index], index);
}
},
);
}

试图在我的程序中运行一个简单的小部件,但收到

"body_ light_complet_;错误

如何更正此问题?

itemBuilder只在(index < _todoItems.length)上返回,您需要确保在每种情况下都返回小部件。

Widget _buildTodoList() {
return   ListView.builder(
itemCount:_todoItems.length, // your list length
itemBuilder: (context, index) {
if (index < _todoItems.length) {
return _buildTodoItem(_todoItems[index], index);
}
return Text("default case");// if above condtions dont meet, return this
},
);
}

最新更新