在我的应用程序中,我在多个页面的横幅,我所有的横幅图像来源是相同的,所有相同的小部件唯一的区别是父小部件。
在模拟器上运行,但不在真实的设备上运行
我的主页,唯一的区别是工作横幅是在行(在所有其他页面,如果它不在行不工作)
Column(
children: [
AspectRatio(aspectRatio: 16 / 9, child: HomePageBanner()),
scrollingItems(),
AspectRatio(
aspectRatio: 16 / 6,
child: Row(
children: [
HomePageBanner(),
HomePageBanner(),
],
),
),
scrollingItems2(),
AspectRatio(
aspectRatio: 16 / 6,
child: Row(
children: [
HomePageBanner(),
HomePageBanner(),
],
),
),
],
),
主页横幅
Expanded(
child: PageView.builder(
onPageChanged: (value) {
_currentPageBanner = value;
},
itemCount: participants.length,
controller: pageController,
itemBuilder: ((context, index) {
return GestureDetector(
onTap: () {
_launchURL(url: participants[index].url);
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 5),
margin: const MarginConstant.all(),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color:
ColorConstants.instance.kPrimaryColor.withOpacity(.3),
blurRadius: 5,
spreadRadius: 1),
],
borderRadius: const RadiusConstant.all(),
color: Colors.white,
),
child: ClipRRect(
borderRadius: const RadiusConstant.all(),
child: Image.asset(
participants[index].imageAsset,
fit: BoxFit.contain,
),
),
),
);
}),
),
);
例外情况
════════ Exception caught by widgets library ═══════════════════════════════════
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 AspectRatio widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
RepaintBoundary ← NotificationListener<ScrollNotification> ← GlowingOverscrollIndicator ← Scrollable ← NotificationListener<ScrollNotification> ← PageView ← Expanded ← HomePageBanner ← AspectRatio ← Column ← ⋯
When the exception was thrown, this was the stack
2条答案
按热度按时间wqlqzqxt1#
正如第三段所述,有问题的Expanded当前被放置在一个AspectRatio小部件中。我使用了作为HomePageBanner,用Expanded Package 它,并用aspectratio Package 它。正确的用法是用AspectRatio Package pagebuilder,它完成了,对于水平横幅,只是用Expanded Package 了我的HomePageBanner。
正确用法
更正主页
rxztt3cl2#
发布模式中出现灰色区域的一个原因是,在使用Expended小部件时忽略调试模式中的警告注解
确保在列和行小部件中以正确方式使用Expended小部件