我正在研究顯示有關我的顫振應用程式資訊的路線。我使用 RichText 和 TextSpan 小部件來顯示指向我的電子郵件和 github 存盤庫的行內超鏈接。這樣不僅可以輕松地為鏈接添加下劃線,還可以輕松定義 TapGestureRecognizer 行為。在測驗時,我發現為了讓這個文本始終出現(無論是 DarkTheme 還是 LightTheme),我需要指示小部件獲取背景關系主題,如下所示:
TextSpan(
text: "\n You may also view this project's source code at ",
style: Theme.of(context).textTheme.bodyText1,
),
但是現在我將一個方法傳遞給 style 屬性,我如何還指定我希望文本也帶有下劃線?在我的樣式屬性閱讀之前:
style: TextStyle(
decoration: TextDecoration.underline,
),
我怎樣才能做到這兩點?
uj5u.com熱心網友回復:
使用copyWith:
final existingStyle = Theme.of(context).textTheme.bodyText1;
TextSpan(
text: "Your text...",
style: existingStyle?.copyWith(
decoration: TextDecoration.underline,
),
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/400742.html
上一篇:放置容器而不是AppBar
下一篇:如何從您指向的路線觸發方法?
