You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter开发:实现多个Text组件分行显示需使用何种Widget?

解决Flutter中Text组件单独分行显示的问题

要让每个Text组件单独分行,最适合的是Column组件——它是垂直方向的线性布局,默认会将子组件从上到下依次排列,每个子组件占据单独一行。

修改后的完整代码如下:

import 'package:flutter/material.dart';

void main() => runApp(const AppMain());

class AppMain extends StatelessWidget {
  const AppMain({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Memo',
      home: Scaffold(
        body: SafeArea(
          child: Column( // 替换为Column组件
            children: const [
              Text("The first text"),
              Text("Second Memo Title"),
              Text("Third One"),
              Text("and so on"),
            ],
          ),
        ),
      ),
      debugShowCheckedModeBanner: false,
    );
  }
}

为什么Wrap组件不行?

Wrap组件的逻辑是:当子组件总宽度超出当前容器宽度时才会自动换行。你的每个Text内容都比较短,不会触发换行逻辑,所以它们会默认横向排列在同一行,达不到每行一个Text的效果。

进阶建议:如果备忘录列表较长

如果后续你的备忘录标题数量较多,用Column可能会出现屏幕溢出的问题,这时推荐使用ListView组件,它支持滚动,能避免溢出:

// 替换Column为ListView
child: ListView(
  children: const [
    Text("The first text"),
    Text("Second Memo Title"),
    Text("Third One"),
    Text("and so on"),
    // 可添加更多Text组件
  ],
),

内容的提问来源于stack exchange,提问作者J. Lee

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 13:45:31