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
相关产品推荐
相关产品推荐

