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(
context: context,
builder: (context) {

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

Loading…
Cancel
Save