微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我突发奇想收到了这个 Renderflex 错误却无法解决它?

如何解决我突发奇想收到了这个 Renderflex 错误却无法解决它?

我试图显示一个星形图标,当用户按下它时,它会显示 5 颗星,以便用户可以投票。但我收到一个错误提示

he 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 Listener widget.

The ownership chain for the RenderObject that received the incompatible parent data was:
  Column ← Expanded ← Container ← Listener ← RawGestureDetector ← GestureDetector ← Semantics ← _RawMouseRegion ← MouseRegion ← Semantics ← ⋯

════════ Exception caught by rendering library ═════════════════════════════════
A RenderFlex overflowed by 74 pixels on the right.
The relevant error-causing widget was
Row
lib/rating.dart/ratingbar.dart:42

我在代码标记错误希望任何人都可以提供帮助,如果您需要更多信息,请留下评论。 当我按下图标上的 并且显示带有“清除”文本的 5 颗星时,错误在线。如果您需要,我会在另一个班级中调用该小部件,也请发表评论

 class ratingpage extends StatefulWidget {
  final int maximumrating;
  final Function(int) onratingSelected;

  ratingpage(this.onratingSelected,[this.maximumrating = 5]);

  @override
  _ratingpageState createState() => _ratingpageState();
}

class _ratingpageState extends State<ratingpage> {
  int _currentrating = 0;
  Widget _buildratingStar(int index) {
    if (index < _currentrating) {
      return Icon(
        Icons.star,color: Colors.yellow,);
    } else {
      return Icon(
        Icons.star,color: Colors.white,);
    }
  }

  Widget _buildBody() {
    final stars = List<Widget>.generate(this.widget.maximumrating,(index) {
      return GestureDetector(
        child: _buildratingStar(index),onTap: () {
          setState(() {
            _currentrating = index + 1;
          });
          this.widget.onratingSelected(_currentrating);
        },);
    });
    return 
Row(here the erroroororoororoorororoororoororororoorororoorororooror
      mainAxisAlignment: MainAxisAlignment.end,children: [
        Row( 
            children: stars,),TextButton(
          onpressed: () {
            setState(() {
              _currentrating = 0;
            });
            this.widget.onratingSelected(_currentrating);
          },child: Text(
            "Clear",style: TextStyle(color: Colors.white),],);
  }

  @override
  Widget build(BuildContext context) {
    return _buildBody();
  }
}

我试图用扩展包装但没有帮助。也许任何人都可以帮忙

解决方法

不看代码我真的无法判断,但错误表明扩展的小部件有错误的祖先。

Expanded 必须是 Row、Column 或 Flex 小部件的后代,如果它不起作用,您可能尝试在无法使用的地方使用 Expanded()。

也许这就是你想要的

return Row(
  mainAxisAlignment: MainAxisAlignment.end,children: [
    Row(
      children: [
        Expanded(
          child: Container(
            color: Colors.amber,width: 100,),],);`

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?