flutter SingleChildScrollView像素溢出

py49o6xq  于 2023-04-22  发布在  Flutter
关注(0)|答案(1)|浏览(103)

我有一个文本溢出像素的视图。我想有一个设置的高度和所有的文本内的高度将滚动的文本。

var _httpData = Builder(builder: (BuildContext context) {
return Expanded(
    child: StreamBuilder<String>(
  stream: RepositoryHttp()
      .getHttpData
      .dataFromHttp(),
  builder: (context, dataSnapshot) {
    if (dataSnapshot.hasData) {
      return Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          mainAxisSize: MainAxisSize.min,
          children: [
            SingleChildScrollView(
                scrollDirection: Axis.vertical,
                padding: EdgeInsets.all(10),
                child: Stack(
                  children: <Widget>[
                    Text(dataSnapshot.data!,
                        style:
                            TextStyle(color: Colors.white, fontSize: 18)),
                    //overflow: TextOverflow.ellipsis,
                    //maxLines: 10,
                  ],
                ))
          ]);
    } else {
      return Column(
        children: [
          Text(Strings.noUpdateData),
        ],
      );
    }
  },
));

});
因此,我得到的数据应该只有例如100的高度,如果有更多的'文本/数据'从http它应该仍然只有100的高度,但滚动,使用户可以看到所有的文本。

eyh26e7m

eyh26e7m1#

使用此代码来实现您的目标

return Scaffold(
      body: Center(
        child: Container(
          height: 100,
          margin: EdgeInsets.symmetric(horizontal: 16),
          padding: EdgeInsets.symmetric(vertical: 12),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(2),
            border: Border.all(color: Colors.black),
          ),
          child: SingleChildScrollView(
              scrollDirection: Axis.vertical,
              padding: EdgeInsets.all(10),
              child: Text(
                "I have a view with a text that overflow pixels. I want to have the text to a set height and all text inside that height would be scrollable. So the data I get back should only be for example 100 in height and if there is more 'text/data' from http it should still only be 100 in height but scrollable so user can see all text. I have a view with a text that overflow pixels. I want to have the text to a set height and all text inside that height would be scrollable. So the data I get back should only be for example 100 in height and if there is more 'text/data' from http it should still only be 100 in height but scrollable so user can see all text.",
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 18,
                ),
              )),
        ),
      ),
    );

在此处检查output

相关问题