TextSelectionThemeData is not changing selectionHandleColor in flutter - flutter

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.

Related

flutter how remove text underline on text selection (TextFormField)?

It is necessary to move the cursor to the end of the text, but in flutter this is strangely implemented through text selection, I do it like this
textController.selection =
TextSelection.collapsed(offset: textController.text.length);
it works, but when typing, it appears underlined
It is possible to somehow remove the underlining of the text, I read the documentation, but did not find it.
My TextFormField
TextFormField(
cursorColor: Colors.white,
style: const TextStyle(
color: Colors.white,
fontSize: 20,
),
controller: textController,
autofocus: false,
decoration: const InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
filled: true,
isDense: true,
hintText:
'search',
hintStyle: TextStyle(
//Style of hintText
color: Colors.white60,
fontSize: 20,
),
),
),
This might help you:
TextField(
style: const TextStyle(
decoration: TextDecoration.none),
),

Flutter TextField label is outside of background when focused

Title should say everything. Nevertheless, here are some pictures for better understanding.
How it should look like (Google Material Components):
How it actually looks like:
But please ignore the bottom border of the pic "how it should look like". The problem is just that the label is outside of the background.
And also the Text and LabelText is not vertically centered. Another picture:
I also tried playing around with the paddings (top and bottom) but either it didn't change anything or I got an error.
And here is the source code:
return TextField(
onChanged: (String? value) {
print(value);
onChanged(value);
},
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
prefixIcon: prefixIcon,
labelText: labelText,
labelStyle: TextStyle(
fontWeight: FontWeight.w700,
color: kInputColor,
fontSize: 14.0,
),
filled: true,
fillColor: kInputFillColor,
contentPadding: EdgeInsets.only(
top: 14.0,
bottom: 14.0,
left: 14.0,
right: 14.0,
),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(6.0),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(6.0),
),
),
cursorWidth: 1.5,
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.black,
fontSize: 14.0,
),
);
The problem was the type of border I used. Through the answer of #Diwyansh, I found out that the default border a TextField uses is the UnderlineInputBorder. I found out that this type of border also has the properties to set borderRadius and borderSide. So when I use UnderlineInputBorder instead of OutlineInputBorder (which for me sounded more meaningful than UnderlineInputBorder), the label is drawn within the background of the TextField. This is how my source code looks now:
return TextField(
onChanged: (String? value) {
print(value);
onChanged(value);
},
decoration: InputDecoration(
prefixIcon: prefixIcon,
labelText: labelText,
labelStyle: TextStyle(
fontWeight: FontWeight.w700,
color: kInputColor,
fontSize: 14.0,
),
filled: true,
fillColor: kInputFillColor,
contentPadding: EdgeInsets.only(
top: 14.0,
bottom: 12.0,
left: 14.0,
right: 14.0,
),
border: UnderlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
borderSide: BorderSide.none,
),
),
cursorWidth: 1.5,
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.black,
fontSize: 14.0,
),
);
You can get it InputDecoration Property
TextFormField(
decoration: InputDecoration(
labelText: "Label",
filled: true),
)
According to The Official Flutter Documentation of OutlineInputBorder https://api.flutter.dev/flutter/material/OutlineInputBorder/OutlineInputBorder.html
InputDecoration.floatingLabelBehavior, which should be set to FloatingLabelBehavior.never when the borderSide is BorderSide.none. If let as FloatingLabelBehavior.auto, the label will extend beyond the container as if the border were still being drawn.
Which means if BorderSide is set to BorderSide.none, just like you did, the label would look outside the background container when focused.
so you just need to set floatingLabelBehavior to FloatingLabelBehavior.never.
which would make it work like hintText

How to change TextField underline border color when it is desabled

I want to change TextFiled underline color when it is disabled
child: TextField(
***enabled: false,***
controller: resultController,
style: TextStyle(
color: Colors.orange, fontSize: 18, fontWeight: FontWeight.bold),
keyboardType: TextInputType.number,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white)),
),
Look at the below code, it will easily solve your problem:
TextField(
decoration: InputDecoration(
hintText: "Your hint here",
//defalult border
border: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.green)),
//disabled border
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.grey)),
//enabled border
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.blue)),
//error boreder
errorBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.red)),
//focused border
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.purple)),
//error while focused border
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.amber)),
),
),
I am unsure that there is a method you can use to check if a TextField is disabled, but a way you can do it is you can create a bool that keeps track if the TextField is disabled.
Create the bool
bool isDisabled = false;
Make a function that changes the value
Function<void> changeDisabled() {
setState() {
isDisabled ? isDisabled = false : isDisabled = true
}
}
Check the status of isDisabled in your code.
child: TextField(
enabled: false,
controller: resultController,
style: TextStyle(
color: Colors.orange, fontSize: 18, fontWeight: FontWeight.bold),
keyboardType: TextInputType.number,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: isDisabled ? Colors.white : Colors.black)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white)),
),
You can specify the underline color of the TextField if its disabled in the same way you did for when its enabled by using the disabledBorder property of the InputDecoration like :
InputDecoration(
enabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.white)),
labelText: resultLableText,
labelStyle: TextStyle(color: Colors.white),
disabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.green)),
),
or specifying it in the ThemeData like :
MaterialApp(
theme: ThemeData.light().copyWith(
inputDecorationTheme: InputDecorationTheme(
disabledBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.green)),
)),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}

Underline multiple lines in single TextField - Flutter/Dart

Looking to have a TextField which has multiple rows but also an underline for each row. When typing text it should continue to the next row without needing the return key.
Current:
TextField(
maxLines: 2,
decoration: InputDecoration(
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.black,
width: 1.0,
style: BorderStyle.solid),
),
),
)
Current Output:
Desired Output:
this will work for you I guess
TextField(
keyboardType: TextInputType.multiline,
minLines: 100,
maxLines: 500,
style: TextStyle(
decoration: TextDecoration.underline,
),
decoration: InputDecoration(
enabledBorder: InputBorder.none,
hintText: 'Notes.....',
hintStyle: TextStyle(color: Colors.black87),
),
),
If you'd still like to change the color or type or density of the underline use the decorationStyle,decorationColor, and decorationThickness properties.

How to add an extra label within TextFormField?

Is there a way to position "Forget password" label inside a TextFormField?
On a sample picture put forget password? right inside the input
new TextFormField(
decoration: InputDecoration(labelText: 'Password',
labelStyle: TextStyle(
color: Colors.black87,
fontSize: 17,
fontFamily: 'AvenirLight'
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.purple),
),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey,
width: 1.0)
),
),
style: TextStyle(
color: Colors.black87,
fontSize: 17,
fontFamily: 'AvenirLight'
),
controller: _passwordController,
obscureText: true,
),
use the Suffix: property of - InputDecoration:
TextFormField(
decoration: InputDecoration(
suffix: GestureDetector(
onTap: () {
print('tapped');
},
child: Text(
'Forgot Password?',
style: TextStyle(
color: Colors.blue, fontWeight: FontWeight.bold),
),
),
labelText: 'Password',
labelStyle: TextStyle(
color: Colors.black87,
fontSize: 17,
fontFamily: 'AvenirLight'),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.purple),
),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 1.0)),
),
style: TextStyle(
color: Colors.black87, fontSize: 17, fontFamily: 'AvenirLight'),
// controller: _passwordController,
obscureText: true,
),