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

Flutter Markdown表格文本如何实现顶部对齐?

Flutter Markdown表格文本顶部对齐解决方案

要实现表格单元格文本顶部对齐,只需在MarkdownStyleSheet中添加tableCellVerticalAlignment属性并设置为TableCellVerticalAlignment.top即可,这会覆盖组件默认的垂直居中对齐逻辑。

修改后的完整代码如下:

Markdown(
  data: """
|   |   |
|---|---|
|  **09.00** | Test thing about this really long column that should wrap when doingstusfff jasijifjsai jgisajgisajigfaj jsaigfjsaigfjsai jgisajijisjgijasigfj  |
""",
  styleSheet: MarkdownStyleSheet(
    textAlign: WrapAlignment.start,
    h2: TextStyle(
      fontSize: 14,
      fontWeight: FontWeight.bold,
    ),
    code: TextStyle(
      fontSize: 14,
      fontWeight: FontWeight.normal,
      fontFamily: "monospace",
    ),
    codeblockPadding: EdgeInsets.zero,
    tableBorder: TableBorder.all(color: Colors.black, width: 0),
    tableColumnWidth: IntrinsicColumnWidth(),
    tableCellsPadding: EdgeInsets.only(bottom: 10, left: 10),
    tableHeadAlign: TextAlign.start,
    // 添加该行实现单元格文本顶部对齐
    tableCellVerticalAlignment: TableCellVerticalAlignment.top,
  ),
  onTapLink: _markdownLinkHandler,
)

该属性会作用于所有表格单元格,让文本紧贴单元格顶部显示,完全匹配你的需求。

内容的提问来源于stack exchange,提问作者joshpetit

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 06:52:17