gpt4 book ai didi

flutter - 如何将 CupertinoDatePicker 保持在屏幕底部而不是整个屏幕?

转载 作者:行者123 更新时间:2023-12-01 21:55:29 25 4
gpt4 key购买 nike

所以,我在我的应用程序中实现了一个 CupertinoDatePicker,但是当我尝试访问它时,它显示在整个屏幕上,而不仅仅是底部。

代码如下:

onPressed: () {
showCupertinoModalPopup(
context: context,
builder: (BuildContext context) => CupertinoDatePicker(
mode: CupertinoDatePickerMode.dateAndTime,
onDateTimeChanged: (DateTime date) {
_dateTime = date;
}),
);
},

我想知道为什么会这样。引用文档也无济于事。

最佳答案

试试这个:

    class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

// Value that is shown in the date picker in dateAndTime mode.
DateTime dateTime = DateTime.now();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: RaisedButton(
onPressed: () {
showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return _buildBottomPicker(
CupertinoDatePicker(
mode: CupertinoDatePickerMode.dateAndTime,
initialDateTime: dateTime,
onDateTimeChanged: (DateTime newDateTime) {
if (mounted) {
print("Your Selected Date: ${newDateTime.day}");
setState(() => dateTime = newDateTime);
}
},
),
);
},
);
},
child: Text('show date picker'),
),
),
);
}
double _kPickerSheetHeight = 216.0;
Widget _buildBottomPicker(Widget picker) {
return Container(
height: _kPickerSheetHeight,
padding: const EdgeInsets.only(top: 6.0),
color: CupertinoColors.white,
child: DefaultTextStyle(
style: const TextStyle(
color: CupertinoColors.black,
fontSize: 22.0,
),
child: GestureDetector(
// Blocks taps from propagating to the modal sheet and popping.
onTap: () {},
child: SafeArea(
top: false,
child: picker,
),
),
),
);
}

}

enter image description here

关于flutter - 如何将 CupertinoDatePicker 保持在屏幕底部而不是整个屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57754745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com