如何将Textfield光标的颜色更改为Black flutter中的黑色?

发布于 2025-02-13 05:26:55 字数 3044 浏览 1 评论 0原文

我想将默认的蓝色光标颜色更改为flutter textfield时的颜色,为黑色。这是我所指的图像:

”在此处输入图像说明”

代码:

import 'package:flutter/material.dart';

class test extends StatefulWidget {
  const test({Key? key}) : super(key: key);

  @override
  State<test> createState() => _testState();
}

class _testState extends State<test> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF6F6F6),
      body: Center(
        child: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: const [
             
              Center(
                child: SizedBox(
                  width: 350,
                  child: TextField(
                    decoration: InputDecoration(
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Color(0xffD7D7D7)),
                      ),
                      focusedBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Color(0xffD7D7D7)),
                      ),
                    ),
                    style: TextStyle(
                      fontSize: 20,
                      decoration: TextDecoration.none,
                      decorationStyle: TextDecorationStyle.dotted,
                      decorationColor: Color(0xffF6F6F6),
                      fontStyle: FontStyle.normal,
                      fontWeight: FontWeight.normal,
                      color: Color(0xff3B3B3B),
                    ),
                  ),
                ),
              ),
     
              Center(
                child: SizedBox(
                  width: 350,
                  child: TextField(
                    decoration: InputDecoration(
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Color(0xffD7D7D7)),
                      ),
                      focusedBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Color(0xffD7D7D7)),
                      ),
                    ),
                    style: TextStyle(
                      fontSize: 20,
                      decoration: TextDecoration.none,
                      decorationStyle: TextDecorationStyle.dotted,
                      decorationColor: Color(0xffF6F6F6),
                      fontStyle: FontStyle.normal,
                      fontWeight: FontWeight.normal,
                      color: Color(0xff3B3B3B),
                    ),
                  ),
                ),
              ),
             
            ],
          ),
        ),
      ),
    );
  }
}

我了解如何更改下划线颜色,但我特别困难地更改闪烁光标的颜色(“ |”字符)。我该如何实现?

I want to change the default blue cursor color in a Flutter TextField to black when it's focused. Here's an image of what I'm referring to:

enter image description here

Code:

import 'package:flutter/material.dart';

class test extends StatefulWidget {
  const test({Key? key}) : super(key: key);

  @override
  State<test> createState() => _testState();
}

class _testState extends State<test> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xffF6F6F6),
      body: Center(
        child: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: const [
             
              Center(
                child: SizedBox(
                  width: 350,
                  child: TextField(
                    decoration: InputDecoration(
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Color(0xffD7D7D7)),
                      ),
                      focusedBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Color(0xffD7D7D7)),
                      ),
                    ),
                    style: TextStyle(
                      fontSize: 20,
                      decoration: TextDecoration.none,
                      decorationStyle: TextDecorationStyle.dotted,
                      decorationColor: Color(0xffF6F6F6),
                      fontStyle: FontStyle.normal,
                      fontWeight: FontWeight.normal,
                      color: Color(0xff3B3B3B),
                    ),
                  ),
                ),
              ),
     
              Center(
                child: SizedBox(
                  width: 350,
                  child: TextField(
                    decoration: InputDecoration(
                      enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Color(0xffD7D7D7)),
                      ),
                      focusedBorder: UnderlineInputBorder(
                        borderSide: BorderSide(color: Color(0xffD7D7D7)),
                      ),
                    ),
                    style: TextStyle(
                      fontSize: 20,
                      decoration: TextDecoration.none,
                      decorationStyle: TextDecorationStyle.dotted,
                      decorationColor: Color(0xffF6F6F6),
                      fontStyle: FontStyle.normal,
                      fontWeight: FontWeight.normal,
                      color: Color(0xff3B3B3B),
                    ),
                  ),
                ),
              ),
             
            ],
          ),
        ),
      ),
    );
  }
}

I understand how to change the underline color, but I'm specifically having trouble changing the color of the blinking cursor (the "|" character). How can I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聚集的泪 2025-02-20 05:26:55

使用CursorColorTextfield的光标更改颜色

TextField(
   cursorColor: Colors.black, //add this line
)

Use cursorColor to change color for cursor of TextField

TextField(
   cursorColor: Colors.black, //add this line
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文