本文介绍了我的.map方法在功能上无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么.map方法被完全忽略.即使删除条件后,它也不会将小部件添加到我的列表中.看来groupsToRename.map()根本不存在.

I dont know why the method .map is totally ignored. Even after deleted conditions, it doesnt add widgets to my list. It seems like groupsToRename.map() doesnt exist at all.

List<Widget> listRenamedGroups(
          List<MapEntry<int, String>> groupsToRename) {
        final List<Widget> resultList = [];
        final currentGroups =
            (bloc.state as ListSuccessfullState<GroupViewModel>).viewModels;
        groupsToRename.map((groupRenameEntry) {
          final correspondingOldEntry = currentGroups
              .firstWhere((element) => element.groupId == groupRenameEntry.key);
          if (correspondingOldEntry == null ||
              correspondingOldEntry.name != groupRenameEntry.value) {
            resultList.add(Text(
              '${correspondingOldEntry.name} --> ${groupRenameEntry.value}',
              textAlign: TextAlign.center,
              style: const TextStyle(
                  fontWeight: FontWeight.w600,
                  fontSize: 20,
                  color: ColorsExtension.textGreyLight),
            ));
          }
        });
        return resultList;
      }

推荐答案

map()之后添加 toList(),或将地图替换为forEach

Add toList() after map(), or replace map with forEach

这篇关于我的.map方法在功能上无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:54