creativecreatorormaybenot
creativecreatorormaybenot

Reputation: 126994

Text Cursor Handle stays Blue

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:

Upvotes: 2

Views: 260

Answers (1)

NiklasPor
NiklasPor

Reputation: 9815

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:

Demo

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,
          ),
        ),
      ),
    );
  }
}

Upvotes: 3

Related Questions