I have a function which enables me to show the date picker with a button press.when I press the button I get this bottom overflow
3 Answers
I got this problem too, but I found a solution. Just wrap with FittedBox.
Future<Null> selecionarData() async {
//dataSelecionada is a final DateTime
dataSelecionada = await showDatePicker(
context: context,
initialDate: dataAtual,
firstDate: DateTime(2019),
lastDate: DateTime(2022),
builder: (BuildContext context, Widget child) {
return FittedBox(
child: Theme(
child: child,
data: ThemeData(
primaryColor: Colors.purple[300],
),
),
);
});
}
1 Comment
(BuildContext? context, Widget? child)I solved this problem with this post: https://github.com/flutter/flutter/issues/19744
I basically remove the OK and CANCEL buttom from this, and added to when select date automatically press on one DATE on datepicker.
In yout datapicker.dart:
void _handleYearChanged(DateTime value) {
_vibrate();
setState(() {
_mode = DatePickerMode.day;
_selectedDate = value;
Navigator.pop(context, _selectedDate); //new
});
}
void _handleDayChanged(DateTime value) {
_vibrate();
setState(() {
_selectedDate = value;
Navigator.pop(context, _selectedDate); //new
});
}
I commented on lines 995 and 1017 in which you insert the action
switch (orientation) {
case Orientation.portrait:
return new SizedBox(
width: _kMonthPickerPortraitWidth,
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
header,
new Container(
color: theme.dialogBackgroundColor,
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
picker,
//actions,
],
),
),
],
),
);
case Orientation.landscape:
return new SizedBox(
height: _kDatePickerLandscapeHeight,
child: new Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
header,
new Flexible(
child: new Container(
width: _kMonthPickerLandscapeWidth,
color: theme.dialogBackgroundColor,
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[picker] //, actions],
),
),
),
],
),
);
}
In my opinion, we don't need the CANCEL button and OK button.
Comments
This is a known issue https://github.com/flutter/flutter/issues/18672
There is a suggestion but that doesn't really solve the issue:
When the keyboard appears your app, including the dialog, is being resized to make room for it. This would also happen if you changed the device's orientation from portrait to landscape.
Wrapping the dialog's widget - the one you're building with showDialog's builder parameter - in a SingleChildScrollView or a ListView or a ClipRect (per the error message) will make it resizable.