- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
自从我引入了 PageView 小部件后,我得到了这个错误:
════════ 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 RepaintBoundary widget.
The ownership chain for the RenderObject that received the incompatible parent data was: Padding ← Container ← AnimatedContainer-[LabeledGlobalKey<ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget>>#758ef] ← KeyboardAvoider ← Expanded ← VpFormContainer ← LoggedOutNickNamePage ← RepaintBoundary ← IndexedSemantics ← NotificationListener<KeepAliveNotification> ← ⋯ When the exception was thrown, this was the stack
#0 RenderObjectElement._updateParentData.<anonymous closure> package:flutter/…/widgets/framework.dart:5770
#1 RenderObjectElement._updateParentData package:flutter/…/widgets/framework.dart:5786
#2 RenderObjectElement.attachRenderObject package:flutter/…/widgets/framework.dart:5808
#3 RenderObjectElement.mount package:flutter/…/widgets/framework.dart:5501
#4 SingleChildRenderObjectElement.mount package:flutter/…/widgets/framework.dart:6117 ...
════════ 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 RepaintBoundary widget.
The ownership chain for the RenderObject that received the incompatible parent data was: Padding ← Container ← AnimatedContainer-[LabeledGlobalKey<ImplicitlyAnimatedWidgetState<ImplicitlyAnimatedWidget>>#758ef] ← KeyboardAvoider ← Expanded ← VpFormContainer ← LoggedOutNickNamePage ← RepaintBoundary ← IndexedSemantics ← NotificationListener<KeepAliveNotification> ← ⋯ When the exception was thrown, this was the stack
#0 RenderObjectElement._updateParentData.<anonymous closure> package:flutter/…/widgets/framework.dart:5770
#1 RenderObjectElement._updateParentData package:flutter/…/widgets/framework.dart:5786
#2 RenderObjectElement.attachRenderObject package:flutter/…/widgets/framework.dart:5808
#3 RenderObjectElement.mount package:flutter/…/widgets/framework.dart:5501
#4 SingleChildRenderObjectElement.mount package:flutter/…/widgets/framework.dart:6117 ...
过去几个小时我一直在尝试修复,但没有任何效果。有谁确切知道在哪里应用修复程序以及修复程序是什么?
这是页面 View :
class LoggedOutPageView extends StatelessWidget {
final _controller = PageController(
initialPage: 0,
);
@override
Widget build(BuildContext context) {
print('building loggedOutPageView');
final pageView = PageView(
physics: const NeverScrollableScrollPhysics(),
controller: _controller,
clipBehavior: Clip.none,
children: [
LoggedOutNickNamePage(_controller),
LoggedOutEmailPage(_controller),
LoggedOutPasswordPage(),
],
);
final _pageContent = Expanded(
child: Container(child: pageView, color: Colors.transparent), flex: 1);
final _pageIndicator = Container(
height: 50,
child: SmoothPageIndicator(
controller: _controller,
count: 3,
effect: const JumpingDotEffect(),
),
color: Colors.transparent);
return VpFormPageScaffold([
VpLogoHeader(
onPressed: () {
print(_controller.page);
if (_controller.page > 0) {
_controller.previousPage(
duration: const Duration(milliseconds: 800),
curve: Curves.easeInOutCubic);
} else {
Navigator.pop(context);
}
},
pop: false),
_pageContent,
_pageIndicator
]);
}
}
VpFormPageScaffold:
class VpFormPageScaffold extends StatelessWidget {
VpFormPageScaffold(this.children);
List<Widget> children;
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: ConstrainedBox(
constraints: BoxConstraints.tightFor(
height: MediaQuery.of(context).size.height),
child: VpGradientContainer(
beginColor: initialGradientColor,
endColor: endGradientColor,
child: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: children)))));
}
}
VpGradientContainer:
class VpGradientContainer extends StatelessWidget {
const VpGradientContainer({this.child, this.beginColor, this.endColor});
final Widget child;
final Color beginColor;
final Color endColor;
@override
Widget build(BuildContext context) {
return Container(
child: child,
height: double.infinity,
width: double.infinity,
padding: const EdgeInsets.all(40),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [beginColor, endColor],
),
),
);
}
}
最佳答案
展开的小部件必须放在 Flex 小部件内。您正在使用无法使用的扩展小部件。您必须从此处删除扩展小部件:
final _pageContent = Expanded(
child: Container(child: pageView, color: Colors.transparent), flex: 1);
请查看 Flutter 文档以了解 Expanded小部件:
A widget that expands a child of a Row, Column, or Flexso that the child fills the available space.
Using an Expanded widget makes a child of a Row, Column, or Flexexpand to fill the available space along the main axis (e.g.,horizontally for a Row or vertically for a Column). If multiplechildren are expanded, the available space is divided among themaccording to the flex factor.
An Expanded widget must be a descendant of a Row, Column, or Flex, andthe path from the Expanded widget to its enclosing Row, Column, orFlex must contain only StatelessWidgets or StatefulWidgets (not otherkinds of widgets, like RenderObjectWidgets).
关于Flutter - ParentDataWidget 的不正确使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65151499/
自从我引入了 PageView 小部件后,我得到了这个错误: ════════ Exception caught by widgets library ════════════════════════
Anyne 知道这个错误是什么吗?我认为有些 child 不能放在什么东西里面? 接收到不兼容父数据的 RenderObject 的所有权链是:_GestureSemantics ← RawGestu
我收到错误 ParentDataWidget 的错误使用。 import 'package:flutter/material.dart'; import 'package:font_awesome_f
我是 Flutter 的新手,收到以下错误消息。 错误信息: The following assertion was thrown while applying parent data.: Incor
我是 Flutter 的新手,收到以下错误消息。 错误信息: The following assertion was thrown while applying parent data.: Incor
我收到错误错误使用 ParentDataWidget。 并且列表没有第一次显示该项目。 ParentDataWidget Expanded(flex: 1) 想要将 FlexParentData 类型
我正在尝试为我的容器添加背景颜色,然后可能使用 BoxDecoration() 添加一些边框半径。添加 color: Colors.red 到容器时,它会抛出: Incorrect use of Pa
在我申请的这一部分中,我有 ListView ,当我运行应用程序时出现此错误,我无法解决: Scaffold( body: Directionality( textDirection: TextD
以下代码导致错误:ParentDataWidget 的使用不正确。此错误的原因是 Positioned 小部件,但我不确定为什么... return Scaffold( body: Con
以下代码导致错误:ParentDataWidget 的使用不正确。此错误的原因是 Positioned 小部件,但我不确定为什么... return Scaffold( body: Con
我是一名优秀的程序员,十分优秀!