Skip to content

Commit 49abdde

Browse files
Added Option for a start date and max date, also added option to change selected date text color
1 parent 86a95b3 commit 49abdde

File tree

6 files changed

+231
-104
lines changed

6 files changed

+231
-104
lines changed

example/ios/Flutter/flutter_export_environment.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export "SYMROOT=${SOURCE_ROOT}/../build/ios"
88
export "FLUTTER_FRAMEWORK_DIR=/Users/vivek/development/flutter/bin/cache/artifacts/engine/ios"
99
export "FLUTTER_BUILD_NAME=1.0.0"
1010
export "FLUTTER_BUILD_NUMBER=1"
11+
export "TRACK_WIDGET_CREATION=true"

example/lib/main.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,21 @@ class _MyHomePageState extends State<MyHomePage> {
4747
Padding(
4848
padding: EdgeInsets.all(20),
4949
),
50-
DatePickerTimeline(
51-
_selectedValue,
52-
onDateChange: (date) {
53-
// New date selected
54-
setState(() {
55-
_selectedValue = date;
56-
});
57-
},
50+
Container(
51+
child: DatePicker(
52+
DateTime.now(),
53+
width: 60,
54+
height: 80,
55+
startDate: DateTime.now().add(Duration(days: -30)),
56+
selectionColor: Colors.black,
57+
selectedTextColor: Colors.white,
58+
onDateChange: (date) {
59+
// New date selected
60+
setState(() {
61+
_selectedValue = date;
62+
});
63+
},
64+
),
5865
),
5966
],
6067
),

example/pubspec.lock

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
# Generated by pub
22
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
4+
archive:
5+
dependency: transitive
6+
description:
7+
name: archive
8+
url: "https://pub.dartlang.org"
9+
source: hosted
10+
version: "2.0.11"
11+
args:
12+
dependency: transitive
13+
description:
14+
name: args
15+
url: "https://pub.dartlang.org"
16+
source: hosted
17+
version: "1.5.2"
418
async:
519
dependency: transitive
620
description:
721
name: async
822
url: "https://pub.dartlang.org"
923
source: hosted
10-
version: "2.3.0"
24+
version: "2.4.0"
1125
boolean_selector:
1226
dependency: transitive
1327
description:
@@ -29,6 +43,20 @@ packages:
2943
url: "https://pub.dartlang.org"
3044
source: hosted
3145
version: "1.14.11"
46+
convert:
47+
dependency: transitive
48+
description:
49+
name: convert
50+
url: "https://pub.dartlang.org"
51+
source: hosted
52+
version: "2.1.1"
53+
crypto:
54+
dependency: transitive
55+
description:
56+
name: crypto
57+
url: "https://pub.dartlang.org"
58+
source: hosted
59+
version: "2.1.3"
3260
cupertino_icons:
3361
dependency: "direct main"
3462
description:
@@ -53,6 +81,13 @@ packages:
5381
description: flutter
5482
source: sdk
5583
version: "0.0.0"
84+
image:
85+
dependency: transitive
86+
description:
87+
name: image
88+
url: "https://pub.dartlang.org"
89+
source: hosted
90+
version: "2.1.4"
5691
intl:
5792
dependency: transitive
5893
description:
@@ -66,14 +101,14 @@ packages:
66101
name: matcher
67102
url: "https://pub.dartlang.org"
68103
source: hosted
69-
version: "0.12.5"
104+
version: "0.12.6"
70105
meta:
71106
dependency: transitive
72107
description:
73108
name: meta
74109
url: "https://pub.dartlang.org"
75110
source: hosted
76-
version: "1.1.7"
111+
version: "1.1.8"
77112
path:
78113
dependency: transitive
79114
description:
@@ -88,6 +123,13 @@ packages:
88123
url: "https://pub.dartlang.org"
89124
source: hosted
90125
version: "1.8.0+1"
126+
petitparser:
127+
dependency: transitive
128+
description:
129+
name: petitparser
130+
url: "https://pub.dartlang.org"
131+
source: hosted
132+
version: "2.4.0"
91133
quiver:
92134
dependency: transitive
93135
description:
@@ -141,7 +183,7 @@ packages:
141183
name: test_api
142184
url: "https://pub.dartlang.org"
143185
source: hosted
144-
version: "0.2.5"
186+
version: "0.2.11"
145187
typed_data:
146188
dependency: transitive
147189
description:
@@ -156,5 +198,12 @@ packages:
156198
url: "https://pub.dartlang.org"
157199
source: hosted
158200
version: "2.0.8"
201+
xml:
202+
dependency: transitive
203+
description:
204+
name: xml
205+
url: "https://pub.dartlang.org"
206+
source: hosted
207+
version: "3.5.0"
159208
sdks:
160-
dart: ">=2.2.2 <3.0.0"
209+
dart: ">=2.4.0 <3.0.0"

lib/date_picker_timeline.dart

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,3 @@
11
library date_picker_timeline;
22

3-
import 'package:date_picker_timeline/date_widget.dart';
4-
import 'package:date_picker_timeline/extra/color.dart';
5-
import 'package:date_picker_timeline/extra/style.dart';
6-
import 'package:date_picker_timeline/gestures/tap.dart';
7-
import 'package:flutter/material.dart';
8-
import 'package:intl/date_symbol_data_local.dart';
9-
10-
class DatePickerTimeline extends StatefulWidget {
11-
double width;
12-
double height;
13-
14-
TextStyle monthTextStyle, dayTextStyle, dateTextStyle;
15-
Color selectionColor;
16-
DateTime currentDate;
17-
DateChangeListener onDateChange;
18-
int daysCount;
19-
String locale;
20-
21-
// Creates the DatePickerTimeline Widget
22-
DatePickerTimeline(
23-
this.currentDate, {
24-
Key key,
25-
this.width,
26-
this.height = 80,
27-
this.monthTextStyle = defaultMonthTextStyle,
28-
this.dayTextStyle = defaultDayTextStyle,
29-
this.dateTextStyle = defaultDateTextStyle,
30-
this.selectionColor = AppColors.defaultSelectionColor,
31-
this.daysCount = 50000,
32-
this.onDateChange,
33-
this.locale = "en_US",
34-
}) : super(key: key);
35-
36-
@override
37-
State<StatefulWidget> createState() => new _DatePickerState();
38-
}
39-
40-
class _DatePickerState extends State<DatePickerTimeline> {
41-
42-
@override void initState() {
43-
super.initState();
44-
45-
initializeDateFormatting(widget.locale, null);
46-
}
47-
48-
@override
49-
Widget build(BuildContext context) {
50-
return Container(
51-
width: widget.width,
52-
height: widget.height,
53-
child: ListView.builder(
54-
itemCount: widget.daysCount,
55-
scrollDirection: Axis.horizontal,
56-
itemBuilder: (context, index) {
57-
// Return the Date Widget
58-
DateTime _date = DateTime.now().add(Duration(days: index));
59-
DateTime date = new DateTime(_date.year, _date.month, _date.day);
60-
bool isSelected = compareDate(date, widget.currentDate);
61-
62-
return DateWidget(
63-
date: date,
64-
monthTextStyle: widget.monthTextStyle,
65-
dateTextStyle: widget.dateTextStyle,
66-
dayTextStyle: widget.dayTextStyle,
67-
locale: widget.locale,
68-
selectionColor:
69-
isSelected ? widget.selectionColor : Colors.transparent,
70-
onDateSelected: (selectedDate) {
71-
// A date is selected
72-
if (widget.onDateChange != null) {
73-
widget.onDateChange(selectedDate);
74-
}
75-
setState(() {
76-
widget.currentDate = selectedDate;
77-
});
78-
},
79-
);
80-
},
81-
),
82-
);
83-
}
84-
85-
bool compareDate(DateTime date1, DateTime date2) {
86-
return date1.day == date2.day &&
87-
date1.month == date2.month &&
88-
date1.year == date2.year;
89-
}
90-
}
3+
export 'date_picker_widget.dart';

0 commit comments

Comments
 (0)