Iam trying to globally set the cursor height of Material Textfield using ThemeData
When using the TextField widget you get accessed to a param "cursorHeight" that let’s you change the cursor height.
TextField(
cursorHeight: 15,
);
The problem is I want to have this globally and I can’t figure out how to do that in ThemeData
I would like to do something like that
ThemeData(
inputDecorationTheme: InputDecorationTheme(
cursorHeight: 15
)
)
2
Answers
To globally set the cursor height of a
TextField
usingThemeData
, you can create a customInputDecorationTheme
and apply it to your app’s theme. However, please note thatcursorHeight
is not a direct property ofInputDecorationTheme
. You’ll have to set it as a custom property and then handle it in your customTextField
widget.Here’s an example of how you can achieve this:
In this example, I’ve set the
cursorHeight
property inTextSelectionThemeData
within theThemeData
. This will affect the cursor height for allTextField
widgets in your app.Remember, you’ll need to wrap your
TextField
widgets in aTheme
widget that provides this custom theme data for it to take effect.Keep in mind that this will affect all
TextField
widgets in your app. If you need to have different cursor heights for different parts of your app, you may need to handle it on a case-by-case basis or use more complex customizations.I hope this fixed your issue.
The height of the cursor is determined by the
fontSize
of theTextStyle
applied within the associatedTextField
. By default, this widget utilizes thetitleMedium
attribute of theTextTheme
as its default style. If you customize theTextTheme
property and, in particular, thefontSize
attribute of thetitleMedium
TextStyle
, the cursor’s height will adapt accordingly.