在Flutter中使容器内可滚动文本 [英] Make scrollable Text inside container in Flutter

查看:1681
本文介绍了在Flutter中使容器内可滚动文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在视图内创建可滚动文本:

I'm trying to create a scrollable Text inside a view:

// other widgets,

SingleChildScrollView(
  child: Container(
    height: 200,
    child: Text(
      "Long text here which is longer than the container height"))),

// other widgets

文本长于其父对象的高度容器,但由于某些原因,尽管将文本包装在 SingleChildScrollView 内,但该文本不可滚动。知道我在做什么错吗?

The text is longer than the height of its parent container, but for some reason the text is not scrollable although it is wrapped inside SingleChildScrollView. Any idea what I'm doing wrong?

推荐答案

尝试添加 scrollDirection (水平):

SingleChildScrollView(
scrollDirection: Axis.horizontal,
  child: Container(
      height: 200,
      child: Text(
          "Long text here which is longer than the container height")))

默认为垂直。

或者,如果您想拥有自己的身高,则必须更改顺序( SingleChildScrollView 内部容器):

Or if you want to have with your height then you have to change the order (SingleChildScrollView inside Container):

Container(
    height: 200,
    child: SingleChildScrollView(
        child: Text(
            "Long text here which is longer than the container height")))

这篇关于在Flutter中使容器内可滚动文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆