diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index 1388462079..9b49e297e7 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -229,24 +229,26 @@ class DayPicker extends StatelessWidget { if (day < 1 || day > daysInMonth) { item = new Text(""); } else { - // Put a light circle around the selected day BoxDecoration decoration; - if (selectedDate.year == year && - selectedDate.month == month && - selectedDate.day == day) + TextStyle itemStyle = dayStyle; + + if (selectedDate.year == year && selectedDate.month == month && selectedDate.day == day) { + // The selected day gets a circle background highlight, and a contrasting text color. + final ThemeData theme = Theme.of(context); + itemStyle = itemStyle.copyWith( + color: (theme.brightness == ThemeBrightness.light) ? Colors.white : Colors.black87 + ); decoration = new BoxDecoration( - backgroundColor: themeData.backgroundColor, + backgroundColor: themeData.accentColor, shape: BoxShape.circle ); - - // Use a different font color for the current day - TextStyle itemStyle = dayStyle; - if (currentDate.year == year && - currentDate.month == month && - currentDate.day == day) - itemStyle = itemStyle.copyWith(color: themeData.primaryColor); + } else if (currentDate.year == year && currentDate.month == month && currentDate.day == day) { + // The current day gets a different text color. + itemStyle = itemStyle.copyWith(color: themeData.accentColor); + } item = new GestureDetector( + behavior: HitTestBehavior.translucent, onTap: () { DateTime result = new DateTime(year, month, day); onChanged(result); @@ -285,6 +287,7 @@ class MonthPicker extends StatefulWidget { assert(selectedDate != null); assert(onChanged != null); assert(lastDate.isAfter(firstDate)); + assert(selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate)); } final DateTime selectedDate; @@ -321,6 +324,10 @@ class _MonthPickerState extends State { }); } + int _monthDelta(DateTime startDate, DateTime endDate) { + return (endDate.year - startDate.year) * 12 + endDate.month - startDate.month; + } + List buildItems(BuildContext context, int start, int count) { List result = new List(); DateTime startDate = new DateTime(config.firstDate.year + start ~/ 12, config.firstDate.month + start % 12); @@ -344,8 +351,10 @@ class _MonthPickerState extends State { @override Widget build(BuildContext context) { return new ScrollableLazyList( + key: new ValueKey(config.selectedDate), + initialScrollOffset: config.itemExtent * _monthDelta(config.firstDate, config.selectedDate), itemExtent: config.itemExtent, - itemCount: (config.lastDate.year - config.firstDate.year) * 12 + config.lastDate.month - config.firstDate.month + 1, + itemCount: _monthDelta(config.firstDate, config.lastDate) + 1, itemBuilder: buildItems ); } diff --git a/packages/flutter/lib/src/material/date_picker_dialog.dart b/packages/flutter/lib/src/material/date_picker_dialog.dart index 49696b2415..ff64d649ee 100644 --- a/packages/flutter/lib/src/material/date_picker_dialog.dart +++ b/packages/flutter/lib/src/material/date_picker_dialog.dart @@ -9,6 +9,8 @@ import 'package:flutter/widgets.dart'; import 'dialog.dart'; import 'date_picker.dart'; import 'flat_button.dart'; +import 'theme.dart'; +import 'theme_data.dart'; class _DatePickerDialog extends StatefulWidget { _DatePickerDialog({ @@ -51,6 +53,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { @override Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); return new Dialog( content: new DatePicker( selectedDate: _selectedDate, @@ -61,10 +64,12 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { contentPadding: EdgeInsets.zero, actions: [ new FlatButton( + textColor: theme.accentColor, child: new Text('CANCEL'), onPressed: _handleCancel ), new FlatButton( + textColor: theme.accentColor, child: new Text('OK'), onPressed: _handleOk ), diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 8e5b25818d..1145664a8a 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -61,7 +61,7 @@ class ThemeData { primarySwatch ??= Colors.blue; primaryColor ??= isDark ? Colors.grey[900] : primarySwatch[500]; primaryColorBrightness ??= ThemeBrightness.dark; - accentColor ??= primarySwatch[500]; + accentColor ??= isDark ? Colors.tealAccent[200] : primarySwatch[500]; accentColorBrightness ??= ThemeBrightness.dark; canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50]; cardColor ??= isDark ? Colors.grey[800] : Colors.white;