Flutter 在垂直listview中添加水平listview时不正确使用ParentDataWidget

Flutter 在垂直listview中添加水平listview时不正确使用ParentDataWidget,flutter,listview,dart,Flutter,Listview,Dart,我想在水平listView中添加一个垂直listView,但它总是显示我不正确地使用父数据小部件我尝试过在列小部件周围添加扩展小部件,但不起作用我也尝试过对列进行收缩包装并将其设置为true,但也不起作用 主页 错误消息 应用父数据时引发了以下断言: ParentDataWidget的使用不正确。 已扩展的ParentDataWidget(flex:1)希望将FlexParentData类型的ParentData应用于 RenderObject,已设置为接受不兼容类型ParentData的Par

我想在水平listView中添加一个垂直listView,但它总是显示我不正确地使用父数据小部件我尝试过在列小部件周围添加扩展小部件,但不起作用我也尝试过对列进行收缩包装并将其设置为true,但也不起作用

主页 错误消息
应用父数据时引发了以下断言:
ParentDataWidget的使用不正确。
已扩展的ParentDataWidget(flex:1)希望将FlexParentData类型的ParentData应用于
RenderObject,已设置为接受不兼容类型ParentData的ParentData。
通常,这意味着扩展的小部件具有错误的RenderObjectWidget祖先。典型的
扩展的小部件直接放在Flex小部件中。
有问题的扩展当前放置在RepaitBoundary小部件中。
接收不兼容父数据的RenderObject的所有权链为:
纵队← 扩大← TeamSiteMcCard← 重新绘制边界← 指数符号学←
通知侦听器← 保持活力← 自动开机← 键子树←
银表← ⋯

我用一个容器包装listview并赋予它高度,从而解决了这个问题

扩展的
灵活的
小部件必须位于列或行中。 有关更多信息,您可以参考此和 您不能在该范围之外使用,也不能使用expanded和give physics将listview构建器包装到
NeverScrollableScrollPhysics()

import 'package:provider/provider.dart';

class TeamSearchResultScreen extends StatelessWidget {
  static const routeName = 'team-search-result-screen';
  @override
  Widget build(BuildContext context) {
    final loadedTeams = Provider.of<Teams>(context);
    final loadedCandidates = Provider.of<Candidates>(context);
    return ListView.builder(
      itemBuilder: (ctx, index) => TeamsItemCard(
        teamName: loadedTeams.teams[index].teamName,
        district: loadedTeams.teams[index].teamDistrict,
      ),
      itemCount: loadedTeams.teamsCount,
    );
  }
}

import 'package:election/provider/candidates.dart';
import 'package:election/widgets/candidate_item_card.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class TeamsItemCard extends StatelessWidget {
  final String teamName;
  final String district;
  TeamsItemCard({this.teamName, this.district});
  @override
  Widget build(BuildContext context) {
    final loadedCandidates = Provider.of<Candidates>(context);
    return Expanded(
      child: Column(
        children: [
          Row(
            children: [
              Text(
                teamName,
                style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
              ),
              SizedBox(
                width: 10,
              ),
              Text(
                '-',
                style: TextStyle(fontSize: 18),
              ),
              SizedBox(
                width: 10,
              ),
              Text(
                district,
                style: TextStyle(fontSize: 16),
              ),
            ],
          ),
          ListView.builder(
            shrinkWrap: true,
            scrollDirection: Axis.horizontal,
            itemCount: loadedCandidates.candidatesCount,
            itemBuilder: (ctx, index) => CandidateItemCard(
              name: loadedCandidates.candidates[index].firstName,
              profile: loadedCandidates.candidates[index].image,
            ),
          ),
        ],
      ),
    );
  }
}

import 'package:flutter/material.dart';

class CandidateItemCard extends StatelessWidget {
  final IconData profile;
  final String name;

  CandidateItemCard({this.profile, this.name});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Icon(
          profile,
          size: 16,
        ),
        Text(
          'name',
          style: TextStyle(fontSize: 16),
        ),
      ],
    );
  }
}
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a
RenderObject, which has been set up to accept ParentData of incompatible type ParentData.
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically,
Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a RepaintBoundary widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
  Column ← Expanded ← TeamsItemCard ← RepaintBoundary ← IndexedSemantics ←
NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ←
SliverList ← ⋯