将不变的文本小部件放入FutureBuilder。它已经在当前的实现中构建,如果没有被告知状态是“脏的”,小部件就无法重建。
编辑:考虑在FutureBuilder中包装该列,这可能更有意义,因为该列中的所有小部件都依赖于未来。
这样地:
child:
FutureBuilder<List<Pet>>(
future: API.get_pets(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: [
Text("Actual Pet: " + category.toString()),
Expanded(
child: PageView.builder(
itemCount: number_of_parameters,
itemBuilder: (context, index) {
Pet pet = snapshot.data![index];
category = pet.category.toString();
return Card(
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(15),
image: DecorationImage(
image: image(photoURL).image,
fit: BoxFit.fitWidth),
),
child: Column(children: [
Text ("": category)
]),),);},),),
],
);
return const CircularProgressIndicator();
},},),);```