如何改变flutter中光标底部叶子颜色

问题描述 投票:0回答:1

在下面的代码中,我想将蓝色叶子颜色更改为黑色(已附加图像)我知道如何更改光标颜色,但如何更改此叶子颜色?我什至不确定这是正确的名字

Expanded(
                child: Padding(
                  padding: const EdgeInsets.only(left: 38),
                  child: TextField(
                    cursorColor: Colors.black,
                    style: const TextStyle(
                      color: Colors.black54,
                      fontFamily: 'sen',
                      fontSize: 15,
                    ),
                    decoration: const InputDecoration(
                      border: InputBorder.none,
                      hintText: "Type Message",
                      hintStyle: TextStyle(
                        color: Colors.black54,
                        fontFamily: 'sen',
                        fontSize: 15
                      )
                    ),
                  ),
                ),
              ),
flutter dart android-cursor
1个回答
0
投票

你所说的蓝色叶子叫做

Text selection handle
,你给它起的有趣的名字可能是你没有找到改变颜色的方法的原因。

  1. 更改它的第一种方法是在材质应用程序中定义主色,但我不想这样做,因为它可以用于其他目的
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
        colorScheme: const ColorScheme.dark(
          primary: Colors.yellow, 
        ),
      ),
      home: ...
    );
  }
}
  1. 实际的方法是定义
    TextSelectionThemeData
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
        textSelectionTheme: const TextSelectionThemeData(
          selectionHandleColor: Colors.yellow
        )
      ),
      home: ...
    );
  }
}

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.