Add haptic feedback to date picker
This commit is contained in:
parent
4cd223a7e5
commit
79e92a53a8
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:sky/mojo/activity.dart';
|
||||||
import 'package:sky/theme/colors.dart' as colors;
|
import 'package:sky/theme/colors.dart' as colors;
|
||||||
import 'package:sky/theme/typography.dart' as typography;
|
import 'package:sky/theme/typography.dart' as typography;
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:sky/widgets.dart';
|
||||||
@ -43,12 +44,14 @@ class DatePicker extends StatefulComponent {
|
|||||||
DatePickerMode _mode = DatePickerMode.day;
|
DatePickerMode _mode = DatePickerMode.day;
|
||||||
|
|
||||||
void _handleModeChanged(DatePickerMode mode) {
|
void _handleModeChanged(DatePickerMode mode) {
|
||||||
|
userFeedback.performHapticFeedback(HapticFeedbackType_VIRTUAL_KEY);
|
||||||
setState(() {
|
setState(() {
|
||||||
_mode = mode;
|
_mode = mode;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleYearChanged(DateTime dateTime) {
|
void _handleYearChanged(DateTime dateTime) {
|
||||||
|
userFeedback.performHapticFeedback(HapticFeedbackType_VIRTUAL_KEY);
|
||||||
setState(() {
|
setState(() {
|
||||||
_mode = DatePickerMode.day;
|
_mode = DatePickerMode.day;
|
||||||
});
|
});
|
||||||
@ -56,6 +59,12 @@ class DatePicker extends StatefulComponent {
|
|||||||
onChanged(dateTime);
|
onChanged(dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _handleDayChanged(DateTime dateTime) {
|
||||||
|
userFeedback.performHapticFeedback(HapticFeedbackType_VIRTUAL_KEY);
|
||||||
|
if (onChanged != null)
|
||||||
|
onChanged(dateTime);
|
||||||
|
}
|
||||||
|
|
||||||
static const double _calendarHeight = 210.0;
|
static const double _calendarHeight = 210.0;
|
||||||
|
|
||||||
Widget build() {
|
Widget build() {
|
||||||
@ -69,7 +78,7 @@ class DatePicker extends StatefulComponent {
|
|||||||
case DatePickerMode.day:
|
case DatePickerMode.day:
|
||||||
picker = new MonthPicker(
|
picker = new MonthPicker(
|
||||||
selectedDate: selectedDate,
|
selectedDate: selectedDate,
|
||||||
onChanged: onChanged,
|
onChanged: _handleDayChanged,
|
||||||
firstDate: firstDate,
|
firstDate: firstDate,
|
||||||
lastDate: lastDate,
|
lastDate: lastDate,
|
||||||
itemExtent: _calendarHeight
|
itemExtent: _calendarHeight
|
||||||
@ -167,6 +176,7 @@ class DayPicker extends Component {
|
|||||||
}) {
|
}) {
|
||||||
assert(selectedDate != null);
|
assert(selectedDate != null);
|
||||||
assert(currentDate != null);
|
assert(currentDate != null);
|
||||||
|
assert(onChanged != null);
|
||||||
assert(displayedMonth != null);
|
assert(displayedMonth != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,8 +249,7 @@ class DayPicker extends Component {
|
|||||||
item = new Listener(
|
item = new Listener(
|
||||||
onGestureTap: (_) {
|
onGestureTap: (_) {
|
||||||
DateTime result = new DateTime(year, month, day);
|
DateTime result = new DateTime(year, month, day);
|
||||||
if (onChanged != null)
|
onChanged(result);
|
||||||
onChanged(result);
|
|
||||||
},
|
},
|
||||||
child: new Container(
|
child: new Container(
|
||||||
height: 30.0,
|
height: 30.0,
|
||||||
@ -277,6 +286,7 @@ class MonthPicker extends ScrollableWidgetList {
|
|||||||
double itemExtent
|
double itemExtent
|
||||||
}) : super(itemExtent: itemExtent) {
|
}) : super(itemExtent: itemExtent) {
|
||||||
assert(selectedDate != null);
|
assert(selectedDate != null);
|
||||||
|
assert(onChanged != null);
|
||||||
assert(lastDate.isAfter(firstDate));
|
assert(lastDate.isAfter(firstDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,6 +364,7 @@ class YearPicker extends ScrollableWidgetList {
|
|||||||
this.lastDate
|
this.lastDate
|
||||||
}) : super(itemExtent: 50.0) {
|
}) : super(itemExtent: 50.0) {
|
||||||
assert(selectedDate != null);
|
assert(selectedDate != null);
|
||||||
|
assert(onChanged != null);
|
||||||
assert(lastDate.isAfter(firstDate));
|
assert(lastDate.isAfter(firstDate));
|
||||||
}
|
}
|
||||||
DateTime selectedDate;
|
DateTime selectedDate;
|
||||||
@ -381,8 +392,7 @@ class YearPicker extends ScrollableWidgetList {
|
|||||||
key: new Key(label),
|
key: new Key(label),
|
||||||
onGestureTap: (_) {
|
onGestureTap: (_) {
|
||||||
DateTime result = new DateTime(year, selectedDate.month, selectedDate.day);
|
DateTime result = new DateTime(year, selectedDate.month, selectedDate.day);
|
||||||
if (onChanged != null)
|
onChanged(result);
|
||||||
onChanged(result);
|
|
||||||
},
|
},
|
||||||
child: new InkWell(
|
child: new InkWell(
|
||||||
child: new Container(
|
child: new Container(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user