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
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 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,
),
),
)
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;
},
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.
i am using showModalBottomSheet and given the height of 90% at start. There are two tabs(repeat and onetime) inside bottomsheet, repeat tab has a lot of contents and it is showing perfectly fine with 90% height. But when i tab on onetime tab, i want to decrease the size of bottomsheet to 40% because it does not have more content in it and it does not look nice. But i am unable to change dynamically the height of bottom sheet on pressing onetime tab button.
Can anyone help me how can i achieve this functionality in flutter?
You can use the following code by replacing PutYourWidgetHere() with your custom widget.
void showBottomSheet() {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext context) {
return SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: PutYourWidgetHere(),
));
});
}
dynamically the height and make content in center
showCupertinoModalBottomSheet(
expand: false,
enableDrag: true,
isDismissible: true,
barrierColor: ColorUtils.disableBackground.withAlpha(128),
backgroundColor: ColorUtils.enableBackground,
topRadius: Radius.circular(SizeUtils.minBlock * 4),
context: globalKey.currentState!.context,
builder: (builder) {
return Padding(
padding: EdgeInsets.all(SizeUtils.minBlock * 8),
child: Container(
constraints: BoxConstraints(
minHeight: SizeUtils.blockHeight * 30,
maxHeight: SizeUtils.blockHeight * 60),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [SingleChildScrollView(child: widget)])));
});