在 Flutter 中,当您选择文本时,两个蓝点会出现在所选内容的开头和结尾处。我想将这些点更改为灰色。
我的意思是这样的:
我需要编辑这一行吗?:
selectionHandleColor: Colors.grey,
我可以通过编辑
selectionHandleColor
中的 TextSelectionTheme
属性来实现此目的吗?如果是这样,我应该使用什么值将颜色设置为灰色?
import 'package:flutter/material.dart';
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
@override
Widget build(BuildContext context) {
return TextSelectionTheme(
data: TextSelectionTheme.of(context).copyWith(
selectionHandleColor: Colors.grey, // Assuming this is what you meant
),
child: TextField(/* ... */),
);
}
}
用主题小部件包裹文本字段。并在数据中添加
ThemeData.light().copyWith(
textSelectionHandleColor: Colors.green,
);
ThemeData.dark().copyWith(
accentColor: Colors.green,
textSelectionColor: Colors.green.withOpacity(0.5),
textSelectionHandleColor: Colors.green,
);