我得到以下错误:

即. .,抛出了另一个异常:ParentDataWidget的错误使用。 在移动屏幕上显示错误。

 @override
  Widget build(BuildContext context) {

    return MaterialApp(
      title: widget.title,
      theme: ThemeData.light().copyWith(
        platform: _platform ?? Theme.of(context).platform,
      ),
      home: DefaultTabController(
        length: categoryNames.length,
        child: Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
                 ),
        body: SafeArea(
            child: Column(
              children: <Widget>[
                Chewie(
                  controller: _chewieController,
                ),
                TabBar(
                  labelColor:Colors.black,
                  tabs: categoryNames,
                ),
                Expanded(
                  child: TabBarView(
                    children: [
                      ImageList()
                    ],
                  ),
                )
                /*TabBarView(
                  children: [
                    Icon(Icons.directions_car),
                    Icon(Icons.directions_transit),
                    Icon(Icons.directions_bike),
                  ],
                )*/
              ],
            )
        ),
      ),
      ),
    );
  }

这是我的代码,请检查并让我知道问题。


当前回答

此解决方案仅在使用Position作为行或列的父元素时有效

在我的例子中,我在列中使用了定位。移除它就解决了问题!

Else

始终记住使用“行、列或Flex扩展”

其他回答

在我的例子中,我在Padding小部件中使用Expanded。填充是在一个列内,但由于扩展是由填充包装它给我的错误。简单地删除扩展解决了我的问题。

第一条规则:只在列、行或flex中使用Expanded。

第二条规则:扩展子列的父列也必须用展开来包装

你可以像这样使用Expanded作为scrolling parent的子元素:

Scaffold(
  body: CustomScrollView(
    physics: const AlwaysScrollableScrollPhysics(),
    slivers: [
      SliverFillRemaining(
        fillOverscroll: true,
        child: Column(
          children: <Widget>[
            Container(color: Colors.red,height: 100),
            Expanded(
              child: Container(color: Colors.purple,),
            ),
          ],
        ),
      )
    ],
  ),
)

Expanded不能在Stack中使用。

您应该只在列、行或Flex中使用Expanded

有很多事情可以解决这个问题

在ListView下不使用Spacer Widget 不要在行或列下使用定位 只能使用扩展,必须是列行伸缩的后代