Hover radius flutter data picker - flutter

I’m wondering if there is a possibility to change the hover radius of buttons inside a Date Picker component? The default radius looks too big. Thanks in advance!
Our current code only changes colors, but not the radius of the hover.
return Theme(
data: Theme.of(context).copyWith(
colorScheme: ColorScheme.light(
primary: accentColor, // header background color
onSecondary: colorSecondary,
onPrimary: colorBlack, // header text color
onSurface: colorBlack, // body text color
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: colorBlack, // button text color
),
),
),
child: Center(
child:
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: Responsive.isMobile(context) ? MediaQuery.of(context).size.width : 500.0,
maxHeight: Responsive.isMobile(context) ? MediaQuery.of(context).size.height : 490,
),
child: child,
)
));

try using Theme Widget for date picker
showDatePicker(
builder: (context,child){
return Theme(
data: Theme.of(context).copyWith(
colorScheme: ColorScheme.light(
primary: Colors.black, // header background color
onPrimary: Colors.white, // header text color
onSurface: Colors.black, // body text color
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
primary: Colors.black, // button text color
),
),
),
child: child!,
);
},
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2022),
lastDate: DateTime(2025),
)

Related

How to change disabled color of ElevatedButton and OutlinedButton

There's no such property in ElevatedButton and OutlinedButton widget to change the disabled color like a regular RaisedButton.
ElevatedButton(
onPressed: null,
disabledColor: Colors.brown, // Error
}
Use onSurface property if you only want to change the disabled color (this property is also available in OutlinedButton).
ElevatedButton(
onPressed: null,
style: ElevatedButton.styleFrom(
onSurface: Colors.brown,
),
child: Text('ElevatedButton'),
)
For more customizations, use ButtonStyle:
ElevatedButton(
onPressed: null,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.disabled)) {
return Colors.brown; // Disabled color
}
return Colors.blue; // Regular color
}),
),
child: Text('ElevatedButton'),
)
To apply it for all the ElevatedButton in your app:
MaterialApp(
theme: ThemeData(
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
onSurface: Colors.brown
),
),
),
)
In situation where you want to set an elevated button theme within your app, you can use this:
ThemeData(
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
onSurface: Colors.brown
),
child: Text('ElevatedButton')
))

How to make date picker 'Ok'- and 'Cancel' button text black in Dart Flutter?

I have a date picker in Flutter. I want to make the 'Ok' and 'Cancel' button text black. But I can't find the correct theme setting.
Code displaying the date picker:
Future<void> selectDate(
BuildContext context,
DateTime initialDate,
TextEditingController controller,
Function(DateTime picked, TextEditingController controller) onDatePicked,
String label) async {
final DateTime picked = await showDatePicker(
context: context,
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData(
primarySwatch: Colors.grey,
splashColor: Colors.black,
textTheme: TextTheme(
subtitle1: TextStyle(color: Colors.black),
button: TextStyle(color: Colors.black),
),
accentColor: Colors.black,
colorScheme: ColorScheme.light(
primary: Colors.green[600],
primaryVariant: Colors.black,
secondaryVariant: Colors.black,
onSecondary: Colors.black,
onPrimary: Colors.white,
surface: Colors.black,
onSurface: Colors.black,
secondary: Colors.black),
dialogBackgroundColor: Colors.white,
),
child: child,
);
},
initialDate: initialDate.toLocal(),
firstDate: DateTime(2015, 8).toLocal(),
lastDate: DateTime(2101).toLocal(),
fieldLabelText: label);
if (picked != null) onDatePicked(picked, controller);
}
How it currently looks:
Thanks!
Use this in your ThemeData:
textButtonTheme: new TextButtonThemeData(style: TextButton.styleFrom(primary: Colors.black),),

Changing the trailing icon color in ExpansionTile

I need to change the color of the trailing keyboard_down_arrow in ExpansionTile. I have tried wrapping it in Theme widget and setting accent, primary and IconTheme also, but nothing seems to work.
Theme(
data: Theme.of(context).copyWith(
dividerColor: Colors.transparent,
accentColor: Colors.black,
),
child: ExpansionTile(
//
title: Text("Some Text"
),
childrenPadding: EdgeInsets.symmetric(horizontal: 15),
children: [
],
),
),
I have latest solution with both open/close state:
Theme(
data: Theme.of(context).copyWith(
unselectedWidgetColor: Colors.white, // here for close state
colorScheme: ColorScheme.light(
primary: Colors.white,
), // here for open state in replacement of deprecated accentColor
dividerColor: Colors.transparent, // if you want to remove the border
),
child: ExpansionTile(
...
),
),...
I found the solution to the above problem.
set unselectedWidgetColor property to the color you want in Theme class in flutter.
To change the trailing icon Color you can use the fallowing parameter in Expansion Tile
trailing: Icon(
Icons.keyboard_arrow_down,
color: Colors.green,
),
Example:
ExpansionTile(
//
title: Text("Some Text"),
trailing: Icon(
Icons.keyboard_arrow_down,
color: Colors.green,
),
),
And for theme Color use color: Theme.of(context).primaryColor,

How to customize a TimePicker widget in Flutter

How can you change the Purple selection color, Purple border color, time text color and Hour and Minute color from the input time picker widget, can't seem to find the properties in TimePickerThemeData
showTimePicker(
context: context,
initialTime: TimeOfDay(hour: 10, minute: 47),
builder: (context, child) {
return Theme(
data: ThemeData.light().copyWith(
colorScheme: ColorScheme.light(
// change the border color
primary: Colors.red,
// change the text color
onSurface: Colors.purple,
),
// button colors
buttonTheme: ButtonThemeData(
colorScheme: ColorScheme.light(
primary: Colors.green,
),
),
),
child: child,
);
},
);
Result:
You are able to use states on your theme too! Controlling the styles when making some action (like selected or focused actions).
Here an example:
final theme = ThemeData.light().copyWith(
timePickerTheme: TimePickerThemeData(
backgroundColor: Colors.green.shade200,
hourMinuteColor: MaterialStateColor.resolveWith((states) =>
states.contains(MaterialState.selected)
? Colors.blue.withOpacity(0.2)
: Colors.orange),
hourMinuteTextColor: MaterialStateColor.resolveWith((states) =>
states.contains(MaterialState.selected)
? Colors.pink
: Colors.deepPurple),
dialHandColor: Colors.pink.shade800,
dialBackgroundColor: Colors.purple.withOpacity(0.5),
dialTextColor: MaterialStateColor.resolveWith((states) =>
states.contains(MaterialState.selected)
? Colors.green
: Colors.black),
entryModeIconColor: Colors.yellow
),
textTheme: TextTheme(
overline: TextStyle(
color: Colors.red,
),
),
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
backgroundColor: MaterialStateColor.resolveWith((states) => Colors.black),
foregroundColor: MaterialStateColor.resolveWith((states) => Colors.green),
overlayColor: MaterialStateColor.resolveWith((states) => Colors.pink),
)));

Tooltip message text and background color

I have Image.asset wrapped on Tooltip
Padding(
padding: edgeInsets,
child: Tooltip(preferBelow: false, message: "Miejsca parkingowe ogólnodostępne", child: Image.asset("assets/icons/garage.png", width: _iconSize, height: _iconSize,)),
),
How to set tooltip message text color and background color?
ToolTip supports the decoration named argument, so you don't need to change your top-level theme.
/// Specifies the tooltip's shape and background color.
///
/// If not specified, defaults to a rounded rectangle with a border radius of
/// 4.0, and a color derived from the [ThemeData.textTheme] if the
/// [ThemeData.brightness] is dark, and [ThemeData.primaryTextTheme] if not.
final Decoration decoration;
However, there are other widgets, that include the ToolTip widget in their build method, for example, IconButton where they only support a tooltip as a String, so there's no way currently to change the tooltip style for the IconButton
You can change color of tootip with textStyle attribute. and background color of tooltip with decoration attribute.
Padding(
padding: edgeInsets,
child: Tooltip(textStyle: TextStyle(color: Colors.white),decoration: BoxDecoration(color: Colors.red),text preferBelow: false, message: "Miejsca parkingowe ogólnodostępne",
child: Image.asset("assets/icons/garage.png", width: _iconSize, height: _iconSize,)),
),
I think, Tooltip does'not provide a parameter to change these behaviors but
Tooltip takes the your theme
final ThemeData theme = Theme.of(context);
final ThemeData darkTheme = ThemeData(
brightness: Brightness.dark,
textTheme: theme.brightness == Brightness.dark ? theme.textTheme : theme.primaryTextTheme,
platform: theme.platform,
);
so you can create theme in your MaterialApp (Text color works but backgroundColor does'not work in my app, you can give a try)
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
backgroundColor: Colors.amber,
primaryTextTheme: TextTheme(
body1: TextStyle(
color: Colors.blue,
)
),
primarySwatch: Colors.blue,
),
home: ......
or
This is Tooltip code may be you can change from the source code of the Tooltip which is an bad solution.
return Positioned.fill(
child: IgnorePointer(
child: CustomSingleChildLayout(
delegate: _TooltipPositionDelegate(
target: target,
verticalOffset: verticalOffset,
preferBelow: preferBelow,
),
child: FadeTransition(
opacity: animation,
child: Opacity(
opacity: 0.9,
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: height),
child: Container(
decoration: BoxDecoration(
color: darkTheme.backgroundColor,
borderRadius: BorderRadius.circular(2.0),
),
padding: padding,
child: Center(
widthFactor: 1.0,
heightFactor: 1.0,
child: Text(message, style: darkTheme.textTheme.body1),
),
),
),
),
),
),
),
);
You can create a TooltipThemeData and set it into your top-level ThemeData.
TooltipThemeData(
textStyle: TextStyle(
color: Colors.white,
fontFamily: "Questrial",
fontWeight: FontWeight.bold,
),
decoration: BoxDecoration(
color: Colors.indigo,
borderRadius: BorderRadius.circular(20),
),
);
It's possible set the color of an individual icon's tooltip by setting TooltipTheme as the parent widget, for example as follows:
TooltipTheme(
data: TooltipThemeData(
textStyle: TextStyle(fontSize: 15, color: Colors.white),
decoration: BoxDecoration(
color: Colors.blue[300],
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
),
child: IconButton(
tooltip: 'Icon Title',
icon: Icon(Icons.analytics, color: Colors.black, size: 50),
onPressed: () {}
),
)
As per the documentation.