我有一个功能,使我能够显示日期选择器与按钮press.when我按下按钮,我得到这个底部溢出
发布于 2018-08-21 07:03:11
我用这篇文章解决了这个问题:https://github.com/flutter/flutter/issues/19744
我基本上从其中删除了OK
和CANCEL
按钮,并添加到when select date自动按下日期选择器上的一个DATE
。
在您的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
});
}
我在995和1017行做了注释,您可以在其中插入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],
),
),
),
],
),
);
}
在我看来,我们不需要CANCEL按钮和OK按钮。
发布于 2019-05-18 07:09:33
我也遇到了这个问题,但我找到了一个解决方案。只需使用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],
),
),
);
});
}
https://stackoverflow.com/questions/51934042
复制相似问题