文本光标句柄保持蓝色 [英] Text Cursor Handle stays Blue
问题描述
我尝试了 cursorColor
并将 TextField
包裹在主题$ c $中c>其中
textSelectionHandleColor
和 textSelectionColor
设置为任何颜色,但是文本光标保留蓝色 。
我说的是手柄。以下内容都不适合我:
-
import'package:flutter / material.dart';
void main()=> runApp(MyApp());
类MyApp扩展了StatelessWidget {
@override
Widget build(BuildContext context){
return MaterialApp(
theme:Theme.of(context)。 copyWith(textSelectionHandleColor:Colors.red),
主页:脚手架(
正文:Center(
子级:TextField(
autofocus:true,
),
),
),
);
}
}
I tried
cursorColor
and wrapping theTextField
in aTheme
wheretextSelectionHandleColor
andtextSelectionColor
are set to whatever colors, however, the text cursor stays blue.To be clear, I am talking about the handle. None of the following adjust it for me:
解决方案Sadly, it is currently not possible to change the
textSelectionHandleColor
of aTextField
by modifying its parentTheme
. The onlyTheme
that changes thetextSelectionHandleColor
is theTheme
directly inside theMaterialApp
(source).Issue on GitHub: textSelectionHandleColor is not working/changing. #20219
The reason this problem exists is that the handles are rendered inside an Overlay. The
Overlay
is not a child from theTextField
, but instead always a child of theMaterialApp
. Here is a failed try from another developer to solve the problem: textSelectionHandleColor taken from parent's context. Fixes #20219
Therefore you can currently only adjust the
MaterialApp
inside your application:import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( theme: Theme.of(context).copyWith(textSelectionHandleColor: Colors.red), home: Scaffold( body: Center( child: TextField( autofocus: true, ), ), ), ); } }
这篇关于文本光标句柄保持蓝色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!