如何在本地更改所选文本的颜色-颤振

时间:2020-07-23 18:51:22

标签: flutter dart flutter-layout

可以通过全局设置主题来更改

文本选择颜色:

    theme: ThemeData.light().copyWith(
        accentColor: kPrimaryAccent,
        primaryColor: kPrimaryColor,
        textSelectionColor: kTextSelectionColor,
        textSelectionHandleColor: kPrimaryAccent)

但是如何在单个文本字段中本地完成此操作?

2 个答案:

答案 0 :(得分:1)

您可以用Theme包装小部件,并为其textSelectionColor设置ThemeData

Container(
  child: Theme(
    data: ThemeData(
      textSelectionColor: Colors.yellow,
    ),
    child: SelectableText(
      'this is a text',
    ),
  ),
),

答案 1 :(得分:0)

您有多种选择,这是一些示例:

TextStyle

Text(
  "Test Text",
  style: TextStyle(
      color: Color(// Hex color)
    ),
)

主题

Theme(
  data: Theme.of(context).copyWith(// new ThemeData here),
  child: Text("Test Text"),
)