Commit c2366f33 authored by Hans Muller's avatar Hans Muller

DatePicker et al updates

parent 483ab048
...@@ -229,24 +229,26 @@ class DayPicker extends StatelessWidget { ...@@ -229,24 +229,26 @@ class DayPicker extends StatelessWidget {
if (day < 1 || day > daysInMonth) { if (day < 1 || day > daysInMonth) {
item = new Text(""); item = new Text("");
} else { } else {
// Put a light circle around the selected day
BoxDecoration decoration; BoxDecoration decoration;
if (selectedDate.year == year && TextStyle itemStyle = dayStyle;
selectedDate.month == month &&
selectedDate.day == day) 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( decoration = new BoxDecoration(
backgroundColor: themeData.backgroundColor, backgroundColor: themeData.accentColor,
shape: BoxShape.circle shape: BoxShape.circle
); );
} else if (currentDate.year == year && currentDate.month == month && currentDate.day == day) {
// Use a different font color for the current day // The current day gets a different text color.
TextStyle itemStyle = dayStyle; itemStyle = itemStyle.copyWith(color: themeData.accentColor);
if (currentDate.year == year && }
currentDate.month == month &&
currentDate.day == day)
itemStyle = itemStyle.copyWith(color: themeData.primaryColor);
item = new GestureDetector( item = new GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () { onTap: () {
DateTime result = new DateTime(year, month, day); DateTime result = new DateTime(year, month, day);
onChanged(result); onChanged(result);
...@@ -285,6 +287,7 @@ class MonthPicker extends StatefulWidget { ...@@ -285,6 +287,7 @@ class MonthPicker extends StatefulWidget {
assert(selectedDate != null); assert(selectedDate != null);
assert(onChanged != null); assert(onChanged != null);
assert(lastDate.isAfter(firstDate)); assert(lastDate.isAfter(firstDate));
assert(selectedDate.isAfter(firstDate) || selectedDate.isAtSameMomentAs(firstDate));
} }
final DateTime selectedDate; final DateTime selectedDate;
...@@ -321,6 +324,10 @@ class _MonthPickerState extends State<MonthPicker> { ...@@ -321,6 +324,10 @@ class _MonthPickerState extends State<MonthPicker> {
}); });
} }
int _monthDelta(DateTime startDate, DateTime endDate) {
return (endDate.year - startDate.year) * 12 + endDate.month - startDate.month;
}
List<Widget> buildItems(BuildContext context, int start, int count) { List<Widget> buildItems(BuildContext context, int start, int count) {
List<Widget> result = new List<Widget>(); List<Widget> result = new List<Widget>();
DateTime startDate = new DateTime(config.firstDate.year + start ~/ 12, config.firstDate.month + start % 12); DateTime startDate = new DateTime(config.firstDate.year + start ~/ 12, config.firstDate.month + start % 12);
...@@ -344,8 +351,10 @@ class _MonthPickerState extends State<MonthPicker> { ...@@ -344,8 +351,10 @@ class _MonthPickerState extends State<MonthPicker> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new ScrollableLazyList( return new ScrollableLazyList(
key: new ValueKey<DateTime>(config.selectedDate),
initialScrollOffset: config.itemExtent * _monthDelta(config.firstDate, config.selectedDate),
itemExtent: config.itemExtent, 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 itemBuilder: buildItems
); );
} }
......
...@@ -9,6 +9,8 @@ import 'package:flutter/widgets.dart'; ...@@ -9,6 +9,8 @@ import 'package:flutter/widgets.dart';
import 'dialog.dart'; import 'dialog.dart';
import 'date_picker.dart'; import 'date_picker.dart';
import 'flat_button.dart'; import 'flat_button.dart';
import 'theme.dart';
import 'theme_data.dart';
class _DatePickerDialog extends StatefulWidget { class _DatePickerDialog extends StatefulWidget {
_DatePickerDialog({ _DatePickerDialog({
...@@ -51,6 +53,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -51,6 +53,7 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return new Dialog( return new Dialog(
content: new DatePicker( content: new DatePicker(
selectedDate: _selectedDate, selectedDate: _selectedDate,
...@@ -61,10 +64,12 @@ class _DatePickerDialogState extends State<_DatePickerDialog> { ...@@ -61,10 +64,12 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
actions: <Widget>[ actions: <Widget>[
new FlatButton( new FlatButton(
textColor: theme.accentColor,
child: new Text('CANCEL'), child: new Text('CANCEL'),
onPressed: _handleCancel onPressed: _handleCancel
), ),
new FlatButton( new FlatButton(
textColor: theme.accentColor,
child: new Text('OK'), child: new Text('OK'),
onPressed: _handleOk onPressed: _handleOk
), ),
......
...@@ -61,7 +61,7 @@ class ThemeData { ...@@ -61,7 +61,7 @@ class ThemeData {
primarySwatch ??= Colors.blue; primarySwatch ??= Colors.blue;
primaryColor ??= isDark ? Colors.grey[900] : primarySwatch[500]; primaryColor ??= isDark ? Colors.grey[900] : primarySwatch[500];
primaryColorBrightness ??= ThemeBrightness.dark; primaryColorBrightness ??= ThemeBrightness.dark;
accentColor ??= primarySwatch[500]; accentColor ??= isDark ? Colors.tealAccent[200] : primarySwatch[500];
accentColorBrightness ??= ThemeBrightness.dark; accentColorBrightness ??= ThemeBrightness.dark;
canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50]; canvasColor ??= isDark ? Colors.grey[850] : Colors.grey[50];
cardColor ??= isDark ? Colors.grey[800] : Colors.white; cardColor ??= isDark ? Colors.grey[800] : Colors.white;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment