gpt4 book ai didi

flutter - 没有任何问题,但我仍然收到错误消息

转载 作者:行者123 更新时间:2023-12-04 13:28:01 26 4
gpt4 key购买 nike

我完全按照我想要的方式制作了一个页面。每次我转到该页面时,编译器都会以某种方式向我显示一条错误消息。似乎没有什么不对。一切正常。为什么我每次都会收到这个错误?
我的代码是这样的;

Stack(
children: [
Image.asset(
"assets/someImage.jpg",
fit: BoxFit.cover,
),
Scaffold(
backgroundColor: Colors.transparent,
body: ListView(
children: [
SlimyCard(), // It's a package from pub.dev
Expanded(
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: 20,
itemBuilder: (context, index) {
return ConstrainedBox(
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
minHeight: 50,
maxHeight: 500,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Row(
children: [
Text("Some text"),
Text("Some text."),
Text("Some text.."),
],
),
),
Container(
child: Text("Some text..."),
),
],
),
);
},
),
),
],
),
),
],
);
我尝试删除 ListView 上的 Expanded 并添加其他地方,但一切都在崩溃。
编译器说;
Exception has occurred.
FlutterError (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:
_ScrollSemantics-[GlobalKey#25b39] ← Scrollable ← ListView ← Expanded ← RepaintBoundary ← IndexedSemantics ← NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← ⋯)

最佳答案

我试图理解为什么需要 Expanded,因为 SlimeyCard 将只需要它需要的量,而不是更多。为什么最初使用 Expanded 小部件?
下面的代码对我有用,试试看,如果你得到相同的结果

 return Stack(
children: [
Container(height: 1000,width: double.infinity, color: Colors.white,),// instead of the background image
// Image.asset(
// "assets/someImage.jpg",
// fit: BoxFit.cover,
// ),
Scaffold(
backgroundColor: Colors.transparent,

body: ListView(
children: [
SlimyCard(bottomCardHeight: 500,),
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: 20,
itemBuilder: (context, index) {
return ConstrainedBox(
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
minHeight: 50,
maxHeight: 500,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
child: Row(
children: [
Text("Some text"),
Text("Some text."),
Text("Some text.."),
],
),
),
Container(
child: Text("Some text..."),
),
],
),
);
},
),

],
),
),
],
);

关于flutter - 没有任何问题,但我仍然收到错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66942986/

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