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( () {
now.year, _inAnHour = false;
now.month, setState(() => _selectedDate = DateTime(
now.day, now.year,
startHour + index, now.month,
)), now.day,
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( () {
now.year, _inAnHour = false;
now.month, setState(() => _selectedDate = DateTime(
now.day + offsetDay, now.year,
index, now.month,
)), now.day + offsetDay,
index,
));
},
sameItem, sameItem,
); );
}, },
@ -191,12 +204,15 @@ class _AS2DatePickerState extends State<AS2DatePicker> {
child: ASLongButton.solid( child: ASLongButton.solid(
title: '确认', title: '确认',
onPressed: () { onPressed: () {
Navigator.pop( if (_inAnHour)
context, Navigator.pop(context, true);
RangeDate( else
start: _selectedDate, Navigator.pop(
end: _selectedDate.add(Duration(hours: 1)), context,
)); RangeDate(
start: _selectedDate,
end: _selectedDate.add(Duration(hours: 1)),
));
}, },
), ),
), ),

Loading…
Cancel
Save