I'm trying to achieve flutter DatePicker rounded corner without installing any external packages ,
I tried to make a new custom datepicker and change some of borders in it but don't work . Any suggestion will be great
Don't know if you still need an answer but you can use the dialogTheme of showDatePicker:
await showDatePicker(
context: context,
initialDate: currentDate,
initialDatePickerMode: DatePickerMode.day,
firstDate:
DateTime(currentDate.day, currentDate.month, currentDate.year - 100),
lastDate: DateTime.now(),
builder: (BuildContext context, child) {
return Theme(
data: Theme.of(context).copyWith(
dialogTheme: DialogTheme(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0), // this is the border radius of the picker
),
),
),
child: child!,
);
},
);
Related
I'm developing an app for a small Android device and I want to display a date picker in full screen, so that the buttons take up as much space as possible.
Already tried the answer of Size of the Date Picker in Flutter
as this:
showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(2025),
builder: (context, child) {
return Column(
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: child,
),
],
);
});
but that solution seems to work only to make it smaller.
Note: Also if you can recommend a date picker package that would be great!
I would like the customize the DateRangePicker in flutter to look like the DatePicker.
I am using material 3:
screenshot of DatePicker:
screenshot of DateRangePicker:
Basically in the DateRangePicker you can barely see your selection. I want the background to be as dark as in the DatePicker.
A look at the source code of DateRangePicker reveals that it uses a app bar. I suspect this is the cause of the light color in the header background. But I don't know change that.
This is my code to show the date range picker:
await showDateRangePicker(
context: context,
firstDate: DateTime(1900),
lastDate: DateTime.now(),
);
I manage to achieve what I want thanks to the help of #Rohan Jariwala.
This is what works for me:
await showDateRangePicker(
context: context,
firstDate: DateTime(1900),
lastDate: DateTime.now(),
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
appBarTheme: Theme.of(context)
.appBarTheme
.copyWith(
backgroundColor:
Theme.of(context)
.colorScheme
.primary,
),
),
child: child!,
);
});
You can add builder in showDateRangePicker in following way
builder: (context, Widget? child) => Theme(
data: themeData.copyWith(
appBarTheme: themeData.appBarTheme.copyWith(
backgroundColor: Colors.blue,
iconTheme: themeData.appBarTheme.iconTheme!.copyWith(color: Colors.white)),
colorScheme: ColorScheme.light(
onPrimary: Colors.white,
primary: Colors.red
)),
child: child!,
));
I've added colours to the appBar and colorScheme. You can change those colours.
I have been trying to make the theme of my date picker dynamic i.e. light theme and dark theme based on the system's theme. Although I have been able to successfully create a single theme, I want a dynamic theme behavior from the date picker and am unsure about how to go about it.
final datePickerDarkTheme = ThemeData.light().copyWith(
colorScheme: const ColorScheme.dark(
onPrimary: Colors.black, // selected text color
onSurface: whiteColor, // default text color
primary: orange, // circle color
),
dialogBackgroundColor: grey,
);
showDatePicker(
context: context,
builder: (context, child) {
return Theme(
data: datePickerDarkTheme,
child: child!,
);
},
initialDate: DateTime.now(),
firstDate: DateTime(1800),
lastDate: DateTime(2200),
);
Any help will be appreciated. Thanks!
I want the user to pick the date and time, for that there is date time picker dialogue.
But, is there a way that, I could show the date-time persistently on some flutter widget and use like any other widget?
Container(
child: showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
builder: (BuildContext context, Widget child) {
return Theme(
data: ThemeData.dark(),
child: child,
);
},
);
}
but I cannot use showTimePicker as Widget.
How to use showTimePicker() as widget? so that other widgets can be built on top of it.
I ran into the problem just like you some time ago and I copied the source code and made my custom widget. Now, it can be used like any widget. If you want to adopt this, I want to mention a couple of things.
I am not sure if this works well with localization, I did not test that.
I am not sure if this works on other themes than the light theme, I only tested on the light theme.
You can find the code here.
https://gist.github.com/mithunadhikari40/b55b9990ebc15d0d8bf70fd3f87709b0
Usage:
Copy the code from the above link, create a dart file, paste the code and use it like this:
SizedBox(
child: TimePickerDialog(
initialTime: TimeOfDay.fromDateTime(DateTime.now()),
onTimeChange: (TimeOfDay time) {
print(
"What we get the value of the time is now $time");
},
),
),
You have to open showTimePicker on click of any widget. So you can simply put your code of showTimePicker inside onTap property of the GestureDetector as shown below.
GestureDetector(
onTap: () async {
TimeOfDay picked = await showTimePicker(
context: context,
initialTime: TimeOfDay.now(),
builder: (BuildContext context, Widget child) {
return MediaQuery(
data: MediaQuery.of(context)
.copyWith(alwaysUse24HourFormat: true),
child: child,
);
},);
},
child: Text("SetTime",textAlign: TextAlign.center,));
I am making an ipad in flutter. I have a date picker. But in landscape it is showing pretty big.
Is there any way to resize the date picker dialog
Yes, you can resize date picker dialog by Container(), SizedBox() etc. using it in builder, but only if you put it in something like Column(), for example:
return showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime.now().add(Duration(days: 356)),
builder: (context, child) {
return Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 50.0),
child: Container(
height: 450,
width: 700,
child: child,
),
),
],
);
},
);
With newer flutter version date picker is smaller and no longer takes up most of the screen
https://github.com/flutter/flutter/pull/50546