How to make a fullscreen Date picker in Flutter - flutter

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!

Related

Show TimePicker but not as a pop-up or dialog on the form page

I have to achieve this UI!
But this is part of the page (form).
How can I add this TimePicker as a Widget to Column of the page and have access to its picked time.
SizedBox(
width: MediaQuery.of(context).size.width * 0.44,
child: FittedBox(
child: TimePickerDialog(
initialTime: TimeOfDay.now(),
initialEntryMode: TimePickerEntryMode.input,
),
),
)

Date Picker is not showing when clicking the field - flutter

Im building a registration screen that contains a form of input fields, one of the fields is to input the date of birth from user by showing the Date Picker when the user clicks the field, first i have created an instance of DateFormField and implemented the solution as follows:
//Date picker for birth of date field
final format = DateFormat('dd-mm-yyyy');
final birthDateField = DateTimeField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
),
labelText: 'تاريخ الميلاد',
prefixIcon: Icon(Icons.calendar_month),
),
format: format,
onShowPicker: (context, currentValue) async {
final date = showDatePicker(
context: context,
initialDate: currentValue ?? DateTime.now(),
firstDate: DateTime(1920),
lastDate: DateTime(2022));
return date;
},
);
Then i have rendered the birthDateField inside the Scaffold as follows:
return Scaffold(
backgroundColor: Colors.white,
body: Center(
//Use the SingleChildScrollView as a wrapper to ensure scrolling in case scrolling is needed.
child: SingleChildScrollView(
//wrap the elements with Container to provide flexibility in designing the elements.
child: Container(
color: Colors.white,
//use the form as a container of the input fields as it is a Registration form.
child: Padding(
padding: const EdgeInsets.all(36.0),
child: Form(
//give the form wrapper the key value to tell flutter that this is the form design for your form functions.
key: _formKey,
//use the column to show the elements in vertical array.
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
//Use children property inside the column to specify list of widgets
children: <Widget>[
nameField,
SizedBox(
height: 20,
),
emailField,
SizedBox(
height: 20,
),
passwordField,
SizedBox(
height: 20,
),
confirmPasswordField,
SizedBox(
height: 20,
),
birthDateField,
SizedBox(
height: 20,
),
]),
),
),
),
),
),
);
so after running the code the field appears normally but when clicking its not opening the picker, i tried to set a TextEdittingController i though its updating the state issue but doesn't work and its not showing any errors, i would be thankful if anyone have a idea of whats i am missing.
Note: i have imported the necessary libraries :
import 'dart:io';
import 'package:image_picker/image_picker.dart';
import 'package:intl/intl.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
import 'package:flutter/material.dart';
The issue is here, last date is getting 2022/01/01 and current date is greater than last date.
In order to fix the issue, you need to provide last date which must be greater initial date. You can include lastDate: DateTime(2023)
onShowPicker: (context, currentValue) async {
final date = await showDatePicker(
context: context,
initialDate: currentValue ?? DateTime.now(),
firstDate: DateTime(1920),
lastDate: DateTime(2023));
return date;
},

Make flutter Datepicker rounded at edges

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!,
);
},
);

Widget is not full width

I'm trying to implement https://pub.dev/packages/flutter_date_pickers in my app and trying to make it full width.
I followed the example they provide, but it's still not full width. There's some space on both sides
Flex(
direction: Axis.vertical,
children: [
Expanded(
child: dp.DayPicker(
selectedDate: selectedDate,
onChanged: setNewDate,
firstDate: now,
lastDate: now.add(Duration(days: 365)),
datePickerStyles: dp.DatePickerRangeStyles(),
),
),
],
);
I had the same problem and fixed it by set a width for container widget:
Use this widget in a container with :
width: MediaQuery.of(context).size.width
by this code, you set the width base on the screen.

Size of the Date Picker in Flutter

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