flutter - Flutter Bloc 在 listview.builder 中不起作用?
问题描述
为什么在 listview.builder 事件中没有多次调用:这仅触发一次 time 。
class _UsersQuestionsState extends State<UsersQuestions> {
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return BlocBuilder<QuestionWatcherBloc, QuestionWatcherState>(
builder: (context, state) {
return state.map(
loadInProgress: (_) => const Center(
child: Text("Loading"),
),
loadSuccess: (state) {
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: state.questions.size,
itemBuilder: (
context,
index,
) {
// ignore: avoid_unnecessary_containers
//here i want to read another Bloc event for each index and try to update the state but it's called only one time
context.read<UsersWatcherBloc>().add(
UsersWatcherEvent.watchAllUsers(
state.questions[index].userId.getorCrash()));
return Container(
child: Column(
children: [
Row(children: [
Wrap(
direction: Axis.vertical,
children: [
BlocBuilder<UsersWatcherBloc, UsersWatcherState>(
builder: (context, state) {
return state.map(
empty: (_) => SizedBox(),
initial: (value) => SizedBox(),
loadFailure: (value) => SizedBox(),
loadInProgress: (value) => SizedBox(),
// here i want to use that value but it's not updatin
according to index
loadSuccess: (value) => Text( value.users.first.name.getorCrash()),
);
},
),
我必须显示提出问题的用户名及其详细信息,以便我致电另一个集团并传递他们的用户 ID,并希望根据帖子获得他们的更新名称,但截至目前,我为每个问题获得相同的用户详细信息。bcs 事件是不为每个索引调用。
解决方案
推荐阅读
- amazon-web-services - 我应该如何在 API 网关中设置 lambda 函数的集成请求
- angular - 里面的元素
- azure - JavaScript not working on Azure AD B2C in built user policies signup page
- c# - 如何使用 v 2.7.3 将 MongoDB 集合转换为类
- permissions - 如何获得启用 Glip 创建数据导出任务 API 访问权限?
- java - org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:类'java.lang.String'没有属性'user'
- angular - 角度路线数据树
- automapper - AutoMapper 如何使用计算字段解决
- linux-kernel - linux sysfs 中没有 i2c 节点,需要内核配置吗?
- javafx - 无法切换到第三个场景 JavaFX