TextSelectionThemeData is not changing selectionHandleColor in flutter
Asked Answered
M

1

9

Tested on Both physical device and simulator.

As we all know textSelectionHandleColor is deprecated. So, I decided to make some changes in my app code, unfortunately, selectionHandleColor is still default blue color we get, when we create new app.

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

Cursor color, selection color got changed except handle color. I have tried every possible way to change text selection handle color.

Munro answered 18/10, 2020 at 16:12 Comment(1)
github.com/flutter/flutter/issues/74890Recreation
T
0

One way you can change the cursor color, selection color and handle color is by defining a coloScheme in your MaterialApp widget like so:

  theme: ThemeData(
        appBarTheme: AppBarTheme(
          backgroundColor: your_desired_color,
        ),
        colorScheme: ColorScheme.light(
          // the color for your cursor, selection & handle
          primary: Colors.green, 
        ),
      ),

By defining a primary color, many other widgets in your app will also change color to the primary color. If that's not what you want, you will need to define the colors for your other widgets - case-by-case or in your ThemeData, e.g. Appbar.

enter image description here

Keep in mind that defining your app's colors using a colorScheme is the current best practice for flutter, so it might be a good idea to start migrating to it.

Tambratamburlaine answered 27/3, 2023 at 21:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.