文本光标句柄保持蓝色 [英] Text Cursor Handle stays Blue

查看:89
本文介绍了文本光标句柄保持蓝色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了 cursorColor 并将 TextField 包裹在主题其中 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 the TextField in a Theme where textSelectionHandleColor and textSelectionColor 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 a TextField by modifying its parent Theme. The only Theme that changes the textSelectionHandleColor is the Theme directly inside the MaterialApp (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 the TextField, but instead always a child of the MaterialApp. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆