forked from firka/flutter
Allow date pickers to not have selected date (#132343)
This enables our various date picker classes to have a null `initialDate`. It also fixes the logic of some of the widgets which used to do something when you _changed_ the `initial*` parameters, which is wrong for `initial*` properties (they by definition should only impact the initial state) and wrong for properties in general (behaviour should not change based on whether the widget was built with a new value or not, that violates the reactive design principles). Fixes https://github.com/flutter/flutter/issues/638.
This commit is contained in:
@@ -62,7 +62,7 @@ class _DateTimePicker extends StatelessWidget {
|
||||
Future<void> _selectDate(BuildContext context) async {
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: selectedDate!,
|
||||
initialDate: selectedDate,
|
||||
firstDate: DateTime(2015, 8),
|
||||
lastDate: DateTime(2101),
|
||||
);
|
||||
@@ -120,9 +120,9 @@ class DateAndTimePickerDemo extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
|
||||
DateTime _fromDate = DateTime.now();
|
||||
DateTime? _fromDate = DateTime.now();
|
||||
TimeOfDay _fromTime = const TimeOfDay(hour: 7, minute: 28);
|
||||
DateTime _toDate = DateTime.now();
|
||||
DateTime? _toDate = DateTime.now();
|
||||
TimeOfDay _toTime = const TimeOfDay(hour: 8, minute: 28);
|
||||
final List<String> _allActivities = <String>['hiking', 'swimming', 'boating', 'fishing'];
|
||||
String? _activity = 'fishing';
|
||||
|
||||
Reference in New Issue
Block a user