首页 文章

颤振渲染问题

提问于
浏览
0

我是Flutter移动开发的新手 . 我有一个dart文件从我的localhost获取JSON数据 . 现在我希望在listView中显示数据 .

但我在日志中得到以下内容

I/flutter (23058):   EXCEPTION CAUGHT BY RENDERING LIBRARY 
I/flutter (23058): The following message was thrown during layout:
I/flutter (23058): A RenderFlex overflowed by 242 pixels on the right.

下面是我的代码来显示视图

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Timeline"),
        backgroundColor: Colors.orange,
      ),
      body: ListView.builder(
        shrinkWrap: true,
        itemCount: data == null ? 0 : data.length,
        itemBuilder: (BuildContext context, int index) {
          return Container(
            child: Center(
              child: Row(
                children: <Widget>[
                  new Card(
                    child: new Container(
                      padding: EdgeInsets.all(8.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          new Text(
                            data[index]["text"],
                            softWrap: true,
                            style: new TextStyle(
                              fontFamily: 'Hind',
                              fontSize: 17.0, color: Colors.black87
                            )
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }

This is the screenshot of the rendered screen

1 回答

  • 0

    将您的卡包裹在Expanded小部件中 .

    return Container(
                child: Center(
                  child: Row(
                    children: <Widget>[
                      Expanded(
                        child: new Card(
                          child: new Container(
                            padding: EdgeInsets.all(8.0),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                new Text(data[index],
                                    softWrap: true,
                                    //overflow: TextOverflow.ellipsis,
                                    style: new TextStyle(
                                        fontFamily: 'Hind',
                                        fontSize: 17.0,
                                        color: Colors.black87)),
                              ],
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              );
    

    ScreenShot
    enter image description here

相关问题