gpt4 book ai didi

flutter - 失败的断言行 5120 pos 12 : 'child = _child' is not true

转载 作者:行者123 更新时间:2023-12-03 17:28:40 26 4
gpt4 key购买 nike

我正在尝试使用 bloc 模式创建带有 API 数据的 ListView ,错误如下:

'package:flutter/src/widgets/framework.dart': Failed assertion: line 5120 pos 12: 'child == _child': is not true.



我的列表文件:
import 'package:Instant_Feedback/Dashboard/PeopleList/bloc/bloc.dart';
import 'package:Instant_Feedback/People/strongConnection_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class PeopleListing extends StatefulWidget {
@override
State<StatefulWidget> createState() => _PeopleListingState();
}
class _PeopleListingState extends State<PeopleListing> {
PeopleListBloc peopleBloc;
@override
void initState() {
super.initState();
peopleBloc = BlocProvider.of<PeopleListBloc>(context);
peopleBloc.dispatch(DisplayPeopleList());
}

@override
Widget build(BuildContext context) {
return BlocBuilder(
bloc: peopleBloc,
builder: (context, state){
if (state is PeopleUninitializedState) {
print("PeopleUninitializedState");
} else if (state is PeopleFetchingState) {
print("PeopleFetchingState");
} else if (state is PeopleFetchingState) {
print("PeopleFetchingState");
} else {
final stateAsPeopleFetchedState = state as PeopleFetchedState;
final players = stateAsPeopleFetchedState.people;
return buildPeopleList(players);
}
},
);
}

Widget buildPeopleList(List<StrongConnection_model> people) {
print(people.length);
return Container(
child: Text('sdf sdkfh kdj'),
);
}
}

错误:
enter image description here

最佳答案

问题是,builder()需要一个小部件,而您不会返回 有效小部件 if/else if状况。尝试将您的代码更改为以下版本。

@override
Widget build(BuildContext context) {
return BlocBuilder(
bloc: peopleBloc,
builder: (context, state){
if (state is PeopleUninitializedState) {
<!-- Expects A Widget -->
print("PeopleUninitializedState");
return SizedBox();
} else if (state is PeopleFetchingState) {
<!-- Expects A Widget -->
print("PeopleFetchingState");
return SizedBox();
} else if (state is PeopleFetchingState) {
<!-- Expects A Widget -->
print("PeopleFetchingState");
return SizedBox();
} else {
final stateAsPeopleFetchedState = state as PeopleFetchedState;
final players = stateAsPeopleFetchedState.people;
return buildPeopleList(players);
}
},
);
}

关于flutter - 失败的断言行 5120 pos 12 : 'child = _child' is not true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58213530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com