I have a TextField which looks like this at the moment:
As you can see the selected color is purple. But how can I change that color for that specific TextField ? I do not want to change the AppThemeData. I couldn't find anything on this ... Happy for every help!
you can try and wrap it with Theme and use SplashColor to be something like this :
Theme(
data: ThemeData(textSelectionColor: Colors.green),
child: TextField(
autofocus: false,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: 'Mail',
),
),
);
or do this in main :
theme: ThemeData(
accentColor: Color(0xffBA379B).withOpacity(.6),
primaryColor: Color(0xffBA379B),
textSelectionTheme: TextSelectionThemeData(
selectionColor: Color(0xffBA379B).withOpacity(.5),
cursorColor: Color(0xffBA379B).withOpacity(.6),
selectionHandleColor: Color(0xffBA379B).withOpacity(1),
),
```
Related
In Flutter documentation, it's given
The Material widgets Switch, SwitchListTile, Checkbox, CheckboxListTile, Radio, RadioListTile now use ColorScheme.secondary color for their toggleable widget.
ThemeData.toggleableActiveColor is deprecated and will eventually be removed.
But CheckboxListTile is using ColorScheme.primary for the toggleableActiveColor instead of ColorScheme.secondary
My Main Theme:
ThemeData(
material3 : true,
colorScheme: ColorScheme.fromSeed(
seedColor: DesignColor.green,
primary: DesignColor.green,
onPrimary: DesignColor.primaryTextColor,
secondary: DesignColor.yellow,
onSecondary: DesignColor.white))
My CheckboxListTile:
CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
title: Text(range999),
value: values[1],
onChanged: (val) {})
Output:
Note: The documentation works if i remove usematerial3:true
there is a checkboxTheme property inside ThemeData.
You can update something like this.
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.all<Color>(Colors.purple),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(3),
),
side: BorderSide(color: Colors.grey.shade100, width: 1.5),
),
Happy coding:)
Is there some way to disable the original text background color when selecting text in SelectableText.rich.
Otherwise the original background color(amber for example) is still there, which is different from the selected text background color (blue), and thus making it look like it is not selected.
Wrap it with theme and give it color i hope it helps
Theme(
data: ThemeData(textSelectionColor: Colors.green),
child: SelectableText.rich(
),
),
You need to set your select color first in ThemeData like this:
MaterialApp(
theme: ThemeData(
// use textSelectionTheme and set your needed color instead
textSelectionTheme: TextSelectionThemeData(
selectionColor: Colors.amber,
),
),
),
if need to use just this SelectableText.rich with specific color just wrap your SelectableText.rich with theme:
Theme(
data: ThemeData(
textSelectionTheme: const TextSelectionThemeData(
selectionColor: Colors.amber,
// selectionColor: Colors.transparent, // it can make select color transparent that you need or make that backgroundColor: Color.transparent
),
),
child: const SelectableText.rich(
TextSpan(
children: [
TextSpan(
text: 'test ',
style:
TextStyle(color: Colors.black, backgroundColor: Colors.amber
// this backgroundColor make the white backcolor into amber
),
),
],
),
toolbarOptions: ToolbarOptions(cut: true), // tools like copy, paste
enableInteractiveSelection: false, // you can enable select color
cursorColor: Colors.red, // this is an option if you want change
),
),
This is my theme:
final ThemeData theme = ThemeData();
return MaterialApp(
title: 'Notes',
home: SignInPage(),
debugShowCheckedModeBanner: false,
theme: theme.copyWith(
primaryColor: Colors.green[800],
colorScheme: theme.colorScheme
.copyWith(secondary: Colors.green, secondaryVariant: Colors.green),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: Colors.blue[900],
),
inputDecorationTheme: InputDecorationTheme(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
),
);
In the old days of flutter if you'd put in the primary color to green, the border of the focused text fields would turn green too. Now, I want all of my text fields, when in focus, to have a green border, green prefix icon and green label text, all from the root Theme. But this is the result I get with the code above:
I want the lock, the "password" label, and border to be all green when focused, and grey when not focused. How can I do this from the root Theme of the app. I have the primaryColor set up to green and even the colorScheme secondary color set up to green, but still everything is blue, instead of green.
Add this worked for me
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(color: Color.fromRGBO(126, 132, 138, 1),),
),
The actual way now to change the whole text field colors is by changing the colorScheme.
colorScheme: theme.colorScheme.copyWith(
primary: Colors.green,
),
So in my flutter app, I create TextFormField to use as an input like so (and return it in a scaffold):
final password = TextFormField(
controller: passController,
autofocus: false,
obscureText: true,
decoration: InputDecoration(hintText: 'Password'),
style: new TextStyle(color: Colors.orange),
);
I would like to change the style property inside a themeData, but I couldn't find which property to specify.
The closest one I could get to was textTheme: new TextTheme(body1: new TextStyle(color: Colors.orange)), but this one does nothing to my TextFormField.
How can I set the TextFormField style? Please help, I'm really new to Dart and also programming. I'm currently 13 and I have nobody to help me out with these types of things.
P.S: The complete code is on GitHub if needed: https://github.com/Legolaszstudio/novynotifier
Update:
If you want to change the Text within TextField by Theme of your Flutter App. It's now subtitle1 of TextTheme.
textTheme: TextTheme(
subtitle1: TextStyle(color: Colors.blue),
)
Uhm! That's a long question. TextFormField are subclass of the TextField. The default style of TextField could be found from source below.
final TextStyle style = themeData.textTheme.subhead.merge(widget.style);
So, you have 2 solutions for your source code.
Solution 1
Delete style property are inputted to password.
final password = TextFormField(
controller: passController,
autofocus: false,
obscureText: true,
decoration: InputDecoration(hintText: 'Password'),
style: new TextStyle(color: Colors.orange), // ★ => Delete this.
);
Define a custom subhead style from DataTheme and input into Material app.
MaterialApp(
theme: ThemeData(
textTheme: TextTheme(
subhead: TextStyle(color: Colors.orange),
),
),
home: null,
)
Solution 2
Define a custom subhead style from DataTheme and input into Material app.
MaterialApp(
theme: ThemeData(
textTheme: TextTheme(
subhead: TextStyle(color: Colors.orange),
),
),
home: null,
)
Copy this subhead style into password
final themes = Theme.of(context);
final password = TextFormField(
controller: passController,
autofocus: false,
obscureText: true,
decoration: InputDecoration(hintText: 'Password'),
style: themes.textTheme.subhead, // ★ => Update this.
);
I believe you are looking for subhead
textTheme: TextTheme(
subhead: TextStyle(color: Colors.orange),
)
2021 - 2022
The Material spec for typography changed significantly in 2021 and now uses display, headline, title, body, and label types. titleMedium is the one that will effect all of your TextFields and TextFormFields.
This fact is highlighted in the TextTheme class docs as well.
If you're using the the titleMedium TextStyle for something else, you can easily wrap your TextFields and TextFormFields in a Theme widget and update this style specifically for these widgets like this:
Theme(
data: Theme.of(context).copyWith(
textTheme: Theme.of(context).textTheme.copyWith(
titleMedium: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w300,
),
)),
child: TextField()
),
When the user select a text from inside a TextField, the default highlight color is blue. How to change it to green for example ?
2021 answer
Wrap with Theme and use copyWith to preserve other theme data.
Theme(data: Theme.of(context).copyWith(
textSelectionTheme: TextSelectionThemeData(
selectionColor: Colors.green)),
child: TextFormField()
)
Wrap your text widget with theme and assign the color to the textSelectionColor property inside ThemeData
refer below code for same:- I have changed the text selection color to green
Theme(
data: ThemeData(textSelectionColor: Colors.green),
child: TextField(
controller: _inputController,
decoration: InputDecoration(hintText: "Input"),
),
),
change the value of textSelectionColor of your ThemeData and it will give you the result you are looking for.
please use this code.
Widget build(BuildContex contex){
return MaterialApp{
debugShowCheckedModeBanner: false,
theme: ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.green,
iconTheme: IconThemeData(
color: kGreenColor,
),
hoverColor: kPrimaryColor,
indicatorColor: kPrimaryColor,
),
}
}