Skip to content

Commit 9896ed9

Browse files
authored
Merge pull request #44 from hasanmhallak/refactor-theming
Refactor theming system with dedicated theme classes.
2 parents 5c031b4 + 0b0644f commit 9896ed9

47 files changed

Lines changed: 6714 additions & 4316 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -59,68 +59,75 @@ final date = await showRangePickerDialog(
5959
);
6060
```
6161

62-
Customize the appearance of the picker by providing optional parameters to the `showDatePickerDialog` or
62+
Customize the appearance of the picker by providing the `theme` parameter to the `showDatePickerDialog` or
6363
`showRangePickerDialog` function.
6464

65+
Use `cellsPadding` on `DaysPickerTheme`, `MonthsPickerTheme`, or `YearsPickerTheme` to control inner padding around each grid cell (around the decorated content). Defaults are `EdgeInsets.zero` for days and `EdgeInsets.symmetric(horizontal: 8, vertical: 16)` for months and years.
66+
67+
Set `isEnabled` to `false` on `DatePickerPlusTheme` for a **view-only** picker: selection, header navigation,
68+
and month swiping are disabled, and accessibility reports controls as disabled.
69+
70+
```dart
71+
DatePicker(
72+
minDate: DateTime(2020, 1, 1),
73+
maxDate: DateTime(2025, 12, 31),
74+
theme: const DatePickerPlusTheme(isEnabled: false),
75+
);
76+
```
77+
6578
```dart
6679
final date = await showDatePickerDialog(
67-
context: context,
68-
initialDate: DateTime(2022, 10, 10),
69-
minDate: DateTime(2020, 10, 10),
70-
maxDate: DateTime(2024, 10, 30),
71-
width: 300,
72-
height: 300,
73-
currentDate: DateTime(2022, 10, 15),
74-
selectedDate: DateTime(2022, 10, 16),
75-
currentDateDecoration: const BoxDecoration(),
76-
currentDateTextStyle: const TextStyle(),
77-
daysOfTheWeekTextStyle: const TextStyle(),
78-
disbaledCellsDecoration: const BoxDecoration(),
79-
disabledCellsTextStyle: const TextStyle(),
80-
enabledCellsDecoration: const BoxDecoration(),
81-
enabledCellsTextStyle: const TextStyle(),
82-
initialPickerType: PickerType.days,
83-
selectedCellDecoration: const BoxDecoration(),
84-
selectedCellTextStyle: const TextStyle(),
85-
leadingDateTextStyle: const TextStyle(),
80+
context: context,
81+
initialDate: DateTime(2022, 10, 10),
82+
minDate: DateTime(2020, 10, 10),
83+
maxDate: DateTime(2024, 10, 30),
84+
width: 300,
85+
height: 300,
86+
currentDate: DateTime(2022, 10, 15),
87+
selectedDate: DateTime(2022, 10, 16),
88+
theme: DatePickerPlusTheme(
89+
headerTheme: const HeaderTheme(
90+
centerLeadingDate: true,
8691
slidersColor: Colors.lightBlue,
87-
highlightColor: Colors.redAccent,
8892
slidersSize: 20,
89-
splashColor: Colors.lightBlueAccent,
90-
splashRadius: 40,
91-
centerLeadingDate: true,
93+
),
94+
daysPickerTheme: const DaysPickerTheme(
95+
cellsPadding: EdgeInsets.all(4),
96+
enabledCellsDecoration: BoxDecoration(
97+
color: Colors.transparent,
98+
),
99+
disabledCellsTextStyle: TextStyle(color: Colors.grey),
100+
),
101+
monthsPickerTheme: const MonthsPickerTheme(
102+
cellsPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
103+
),
104+
yearsPickerTheme: const YearsPickerTheme(
105+
cellsPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
106+
),
107+
),
92108
);
93109
```
94110

95111
```dart
96112
final range = await showRangePickerDialog(
97-
context: context,
98-
initialDate: DateTime(2022, 10, 10),
99-
minDate: DateTime(2020, 10, 10),
100-
maxDate: DateTime(2024, 10, 30),
101-
width: 300,
102-
height: 300,
103-
currentDate: DateTime(2022, 10, 15),
104-
selectedRange: DateTimeRange(start: DateTime(2022), end: Dat(2023)),
105-
selectedCellsDecoration: const BoxDecoration(),
106-
selectedCellsTextStyle: const TextStyle(),
107-
singleSelectedCellDecoration: const BoxDecoration(),
108-
singleSelectedCellTextStyle: const TextStyle(),
109-
currentDateDecoration: const BoxDecoration(),
110-
currentDateTextStyle: const TextStyle(),
111-
daysOfTheWeekTextStyle: const TextStyle(),
112-
disbaledCellsDecoration: const BoxDecoration(),
113-
disabledCellsTextStyle: const TextStyle(),
114-
enabledCellsDecoration: const BoxDecoration(),
115-
enabledCellsTextStyle: const TextStyle(),
116-
initialPickerType: PickerType.days,
117-
leadingDateTextStyle: const TextStyle(),
118-
slidersColor: Colors.lightBlue,
119-
highlightColor: Colors.redAccent,
120-
slidersSize: 20,
121-
splashColor: Colors.lightBlueAccent,
122-
splashRadius: 40,
113+
context: context,
114+
initialDate: DateTime(2022, 10, 10),
115+
minDate: DateTime(2020, 10, 10),
116+
maxDate: DateTime(2024, 10, 30),
117+
width: 300,
118+
height: 300,
119+
currentDate: DateTime(2022, 10, 15),
120+
selectedRange: DateTimeRange(start: DateTime(2022), end: DateTime(2023)),
121+
theme: DatePickerPlusTheme(
122+
headerTheme: const HeaderTheme(
123123
centerLeadingDate: true,
124+
slidersColor: Colors.lightBlue,
125+
),
126+
rangePickerTheme: const RangePickerTheme(
127+
selectedCellsDecoration: BoxDecoration(color: Colors.redAccent),
128+
selectedCellsTextStyle: TextStyle(color: Colors.white),
129+
),
130+
),
124131
);
125132
```
126133

example/lib/main.dart

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,20 @@ class MyApp extends StatelessWidget {
2525
return Scaffold(
2626
appBar: AppBar(),
2727
body: Center(
28-
child: Column(
29-
mainAxisAlignment: MainAxisAlignment.center,
30-
children: [
31-
SizedBox(
32-
height: 400,
33-
child: DatePicker(
34-
centerLeadingDate: true,
28+
child: StatefulBuilder(builder: (context, setState) {
29+
return Column(
30+
mainAxisAlignment: MainAxisAlignment.center,
31+
children: [
32+
DatePicker(
3533
minDate: DateTime(2020),
36-
maxDate: DateTime(2024),
37-
initialDate: DateTime(2023, 1),
38-
disabledDayPredicate: (date) {
39-
return date.weekday == DateTime.sunday || date.weekday == DateTime.saturday;
40-
},
41-
disabledCellsDecoration: const BoxDecoration(
42-
color: Colors.green,
43-
),
34+
maxDate: DateTime(2050),
35+
initialDate: DateTime.now(),
36+
currentDate: DateTime.now(),
37+
selectedDate: DateTime.now(),
4438
),
45-
),
46-
],
47-
),
39+
],
40+
);
41+
}),
4842
),
4943
);
5044
},

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ packages:
4747
path: ".."
4848
relative: true
4949
source: path
50-
version: "5.0.0"
50+
version: "6.0.0"
5151
fake_async:
5252
dependency: transitive
5353
description:

lib/date_picker_plus.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ export 'src/shared/year_picker.dart';
66
export 'src/range/range_picker.dart';
77
export 'src/range/show_range_picker_dialog.dart';
88
export 'src/shared/picker_type.dart';
9+
export 'src/theme/date_picker_plus_theme.dart';
10+
export 'src/theme/header_theme.dart';
11+
export 'src/theme/days_of_the_week_theme.dart';
12+
export 'src/theme/days_picker_theme.dart';
13+
export 'src/theme/months_picker_theme.dart';
14+
export 'src/theme/years_picker_theme.dart';
15+
export 'src/theme/range_picker_theme.dart';
16+
export 'src/theme/ink_response_theme.dart';
17+
export 'src/shared/cell_state.dart';

0 commit comments

Comments
 (0)