【问题标题】:RenderViewport#0d172 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATERenderViewport#0d172 需要-绘制需要-合成-位-更新
【发布时间】:2021-02-22 18:14:18
【问题描述】:

这是我的 Flutter 应用 UI: before

在我从 Firebase 获取数据后,一切都消失了,只显示 appBar。 构建方法:

 Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
    title: Text('Recipes Menu'),
    leading: Icon(Icons.menu),
  ),
  backgroundColor: Colors.deepPurple[50],
  body: ListView(
    children: [
      SizedBox(height: 16,),
      search(),
      SizedBox(height: 8,),
      SizedBox(height:6),
    //  foodCard(),
       const Divider(),
    ], ),  ); }

这是我的代码:

Widget foodCard() {
    return Padding(
      padding: const EdgeInsets.all(10.0),
      child: InkWell (
        onTap: (){
        Navigator.push(context, 
            MaterialPageRoute(builder: (context) => RecipeScreen()));},
                child: Column(
                 mainAxisSize:MainAxisSize.min,
                 children: [
                   Expanded(
                   ListView.builder(itemCount: allRecipes.length,
            itemBuilder: (BuildContext context, int index){
            return Material(
            color: Colors.white,
            elevation: 8.0,
            shadowColor: Colors.blueGrey,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(20.0)),
            child: ClipRRect(
                    borderRadius: BorderRadius.only(topLeft: Radius.circular(20.0)),
                    child: FittedBox(
                          child: Material(
                              color: Colors.white,
                              elevation: 8.0,
                              shadowColor: Colors.blueGrey,
                              child: Row(
                                children: [
                                  Container(
                                      width: 250,
                                      height: 250, 
                                          child: FadeInImage.memoryNetwork(
                                            placeholder: kTransparentImage, height: 200,
                                          fit: BoxFit.fitHeight,
                                          alignment: Alignment.topLeft,
                                             image:
                                              "https://images-gmi-pmc.edge-generalmills.com/087d17eb-500e-4b26-abd1-4f9ffa96a2c6.jpg")),
                                  Container(
                                      padding: const EdgeInsets.all(8.0),
                                      child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Column(children: [
                                      Text(allRecipes[index].name,
                                        style: TextStyle(color: Colors.black54),
                                      ),
                                      Text(allRecipes[index].about,
                                       softWrap: true,),
                                      Divider(),
                                      ButtonBar( alignment: MainAxisAlignment.end,
                                        children: <Widget>[
                                          FlatButton(
                                            child: Text('Like',
                                        style: TextStyle(color: Colors.deepPurple)),
                                            onPressed: () {},
                                          ),
                                          FlatButton(
                                            child: Text('Dislike',
                                        style: TextStyle(color: Colors.deepPurple)),                                      onPressed: () {}, ),
                                        ] ]),))],)))),);},), ],), ) ); 
}

我有这个很长的错误:

ListView

lib\screens\menuScreen.dart:47 ══════════════════════════════════════════════════ ══════════════════════════════ 引发了另一个异常:RenderBox 未布局:RenderSemanticsAnnotations#e62d4 relayoutBoundary=up17 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

════════ 渲染库捕获的异常═══════════════════════════════ RenderBox 未布置:RenderSemanticsAnnotations#e62d4 relayoutBoundary=up17 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': 断言失败:第 1702 行第 12 行:'hasSize' 相关的导致错误的小部件是 列表视图

错误信息:

  RenderFlex#7f39a relayoutBoundary=up10 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE(creator: Column ← _PointerListener ← Listener ← _GestureSemantics ← RawGestureDetector ← GestureDetector ← _RawMouseRegion ← MouseRegion ← Semantics ← _FocusMarker ← Focus ← _ActionsMarker ← ⋯, parentData: <none> (can use size), constraints: BoxConstraints(w=340.0, 0.0<=h<=Infinity), size: MISSING, direction: vertical, mainAxisAlignment: start, mainAxisSize: max, crossAxisAlignment: center, verticalDirection: down)

创建者信息设置为: 列 ← _PointerListener ← 监听器 ← _GestureSemantics ← RawGestureDetector ← GestureDetector ← _RawMouseRegion ← MouseRegion ← 语义 ← _FocusMarker ← Focus ← _ActionsMarker ← ⋯ 另见:https://flutter.dev/layout/ 如果以上方法都不足以解决此问题,请不要犹豫提交错误: https://github.com/flutter/flutter/issues/new?template=BUG.md 相关的导致错误的小部件是: 专栏

报错信息过长,怎么办?

【问题讨论】:

  • 对不起,为什么ListView 里面有ListView
  • 在给定无限高度的情况下,垂直视口出现错误,所以我找到了这个解决方案,所以我尝试了一下。 @ikerfah
  • 尝试将第一个ListView 替换为Column,然后将第二个ListView 替换为Expanded,然后告诉我发生了什么。
  • 我现在做了,但 UI 除了 appBar 之外什么都没有显示,我更新了问题,还有另一个错误 @ikerfah
  • mainAxisSize:MainAxisSize.min 添加到 Column 。你现在可以更新代码吗?

标签: flutter


【解决方案1】:

在我们在 cmets 中讨论过之后,你能试试这个代码吗?你能用同样的代码告诉我吗?请确保您重新启动了应用程序而不是热重载

Widget foodCard() {
    return Padding(
        padding: const EdgeInsets.all(10.0),
        child: InkWell(
          onTap: () {},
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Expanded(
                child: ListView.builder(
                  itemCount: allRecipes.length,
                  itemBuilder: (BuildContext context, int index) {
                    return Material(
                      color: Colors.white,
                      elevation: 8.0,
                      shadowColor: Colors.blueGrey,
                      borderRadius:
                      BorderRadius.only(topLeft: Radius.circular(20.0)),
                      child: ClipRRect(
                        borderRadius:
                        BorderRadius.only(topLeft: Radius.circular(20.0)),
                        child: FittedBox(
                          child: Material(
                            color: Colors.white,
                            elevation: 8.0,
                            shadowColor: Colors.blueGrey,
                            child: Row(
                              children: [
                                Container(
                                    width: 250,
                                    height: 250,
                                    child: FadeInImage.memoryNetwork(
                                        placeholder: kTransparentImage,
                                        height: 200,
                                        fit: BoxFit.fitHeight,
                                        alignment: Alignment.topLeft,
                                        image:
                                        "https://images-gmi-pmc.edge-generalmills.com/087d17eb-500e-4b26-abd1-4f9ffa96a2c6.jpg")),
                                Container(
                                  padding: const EdgeInsets.all(8.0),
                                  child: Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: Column(children: [
                                      Text(
                                        allRecipes[index].name,
                                        style: TextStyle(color: Colors.black54),
                                      ),
                                      Text(
                                        allRecipes[index].about,
                                        softWrap: true,
                                      ),
                                      Divider(),
                                      ButtonBar(
                                          alignment: MainAxisAlignment.end,
                                          children: <Widget>[
                                            FlatButton(
                                              child: Text('Like',
                                                  style: TextStyle(
                                                      color:
                                                      Colors.deepPurple)),
                                              onPressed: () {},
                                            ),
                                            FlatButton(
                                              child: Text('Dislike',
                                                  style: TextStyle(
                                                      color:
                                                      Colors.deepPurple)),
                                              onPressed: () {},
                                            ),
                                          ]),
                                    ]),
                                  ),
                                )
                              ],
                            ),
                          ),
                        ),
                      ),
                    );
                  },
                ),
              )
            ],
          ),
        ));
  }

构建

@override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Recipes Menu'),
          leading: Icon(Icons.menu),
        ),
        backgroundColor: Colors.deepPurple[50],
        body: Column(
          children: [
            SizedBox(
              height: 16,
            ),
            // search(),
            SizedBox(
              height: 8,
            ),
            SizedBox(height: 6),
            Expanded(child: foodCard()),
            Divider(),
          ],
        ),
      );
    }

【讨论】:

  • 我在返回 ChangeNotifierProvider.value(..... 时遇到错误
  • 很抱歉,我复制了我未使用的代码,因为我正在为你测试,我更新了我的答案
  • 没关系,它像以前一样工作。但是当我从 firebase UI 中获取文本时再次发生变化。我会添加截图,请检查它们
  • 如果是因为"allRecipes[index].name"我更新了我的代码
  • 是的,文字中有些东西,就像我之前给你看的照片一样,现在我不知道你是否可以看到这些图像!即使我尝试多次上传它们,它们也对我不可见
猜你喜欢
  • 2020-08-14
  • 2020-09-23
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 2011-08-04
  • 1970-01-01
  • 2020-02-27
  • 1970-01-01
相关资源
最近更新 更多