Cre*_*tor 9 textfield textselection dart flutter
在物理设备和模拟器上进行了测试。
众所周知,textSelectionHandleColor 已被弃用。因此,我决定对我的应用程序代码进行一些更改,不幸的是,selectionHandleColor 仍然是我们创建新应用程序时获得的默认蓝色。
TextSelectionTheme(
data: TextSelectionThemeData(
cursorColor: kLightGreen,
selectionHandleColor: kLightGreen,
selectionColor: kGrey),
child: TextField(
keyboardType: TextInputType.number,
style: TextStyle(
color: kOffWhite,
letterSpacing: 1.5,
),
decoration: InputDecoration(
labelText: 'Label',
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: kLightGreen),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: kLightGreen),
),
hintText: 'Hint',
hintStyle: TextStyle(
color: kOffWhite,
letterSpacing: 1.5,
),
labelStyle: TextStyle(
color: kLightGreen,
letterSpacing: 1.5,
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
除手柄颜色外,光标颜色、选择颜色均已更改。我已尝试了一切可能的方法来更改文本选择手柄颜色。
更改光标颜色、选择颜色和手柄颜色的一种方法是在 MaterialApp 小部件中定义一个 coloScheme,如下所示:
theme: ThemeData(
appBarTheme: AppBarTheme(
backgroundColor: your_desired_color,
),
colorScheme: ColorScheme.light(
// the color for your cursor, selection & handle
primary: Colors.green,
),
),
Run Code Online (Sandbox Code Playgroud)
通过定义主颜色,应用程序中的许多其他小部件也会将颜色更改为主颜色。如果这不是您想要的,您将需要根据具体情况或在您的 ThemeData(例如 Appbar)中定义其他小部件的颜色。
请记住,使用 colorScheme 定义应用程序的颜色是当前 flutter 的最佳实践,因此开始迁移到它可能是一个好主意。
| 归档时间: |
|
| 查看次数: |
1539 次 |
| 最近记录: |