update rangePicker

null_safety
小赖 4 years ago
parent c1af00fcad
commit a19385c108

@ -9,7 +9,10 @@ class RangeDate {
}); });
} }
Future<RangeDate> show2DatePicker(BuildContext context) async { ///`bool``true`,
///
///`RangeDate`
Future<dynamic> show2DatePicker(BuildContext context) async {
return await showModalBottomSheet( return await showModalBottomSheet(
context: context, context: context,
builder: (context) { builder: (context) {

@ -18,6 +18,8 @@ class _AS2DatePickerState extends State<AS2DatePicker> {
start: now, start: now,
end: now.add(Duration(hours: 1)), end: now.add(Duration(hours: 1)),
); );
bool _inAnHour = false;
Widget _buildDayButton(int index, String title) { Widget _buildDayButton(int index, String title) {
bool sameDay = _selectedDay == index; bool sameDay = _selectedDay == index;
return MaterialButton( return MaterialButton(
@ -92,20 +94,28 @@ class _AS2DatePickerState extends State<AS2DatePicker> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
bool sameItem = now.day == _selectedDate.day && bool sameItem = now.day == _selectedDate.day &&
_selectedDate.hour == startHour + index; _selectedDate.hour == startHour + index;
if (index == 0) if (index == 0) {
return _renderButton( return _renderButton(
'一小时内', '一小时内',
() => setState(() => _selectedDate = now), () {
_inAnHour = true;
setState(() => {_selectedDate = now});
},
sameItem, sameItem,
); );
}
_inAnHour = false;
return _renderButton( return _renderButton(
'${startHour + index}:00-${startHour + index + 1}:00', '${startHour + index}:00-${startHour + index + 1}:00',
() => setState(() => _selectedDate = DateTime( () {
_inAnHour = false;
setState(() => _selectedDate = DateTime(
now.year, now.year,
now.month, now.month,
now.day, now.day,
startHour + index, startHour + index,
)), ));
},
sameItem, sameItem,
); );
}, },
@ -121,12 +131,15 @@ class _AS2DatePickerState extends State<AS2DatePicker> {
_selectedDate.hour == index; _selectedDate.hour == index;
return _renderButton( return _renderButton(
'$index\:00-${index + 1}:00', '$index\:00-${index + 1}:00',
() => setState(() => _selectedDate = DateTime( () {
_inAnHour = false;
setState(() => _selectedDate = DateTime(
now.year, now.year,
now.month, now.month,
now.day + offsetDay, now.day + offsetDay,
index, index,
)), ));
},
sameItem, sameItem,
); );
}, },
@ -191,6 +204,9 @@ class _AS2DatePickerState extends State<AS2DatePicker> {
child: ASLongButton.solid( child: ASLongButton.solid(
title: '确认', title: '确认',
onPressed: () { onPressed: () {
if (_inAnHour)
Navigator.pop(context, true);
else
Navigator.pop( Navigator.pop(
context, context,
RangeDate( RangeDate(

Loading…
Cancel
Save