Skip to content

Commit f513099

Browse files
author
Shubham Jitiya
committed
feat: Fixes issue #263: ✨ Support for dark theme
1 parent 836953e commit f513099

28 files changed

+447
-185
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Fixes right icon always shows default icon in `CalendarPageHeader` when providing custom icon. [#432](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/432)
66
- Adds `hideDaysNotInMonth` argument in `cellBuilder` in readme. [#433](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/433)
77
- Fixes `titleColor` of date for `hideDaysNotInMonth: false`.
8+
- Adds support for dark theme. [#263](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/issues/263)
89

910
# [1.3.0 - 12 Nov 2024](https://github.com/SimformSolutionsPvtLtd/flutter_calendar_view/tree/1.3.0)
1011

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,46 @@ WeekView(
354354

355355
Above code will create `WeekView` with only five days, from monday to friday.
356356

357+
## **Customise theme**
358+
* The default theme includes support for dark mode.
359+
* For detailed instructions on how to override the default settings, please refer to [this]() guide.
360+
361+
### Day view
362+
* Default timeline text color is `colorScheme.onSurface`.
363+
* Default hour, half hour & quarter color is `colorScheme.surfaceContainerHighest`.
364+
* Default timeline color `colorScheme.primaryColorLight`.
365+
366+
Default hour indicator settings.
367+
```dart
368+
HourIndicatorSettings(
369+
height: widget.heightPerMinute,
370+
// Color of horizontal and vertical lines
371+
color: Theme.of(context).colorScheme.surfaceContainerHighest,
372+
offset: 5,
373+
);
374+
```
375+
376+
### Week view
377+
* Week-number text color - Default color `onSecondaryContainer`.
378+
* To customise week number & weekdays use `weekNumberBuilder` & `weekDayBuilder`.
379+
* Default week tile color is `colorScheme.surfaceContainerHigh`.
380+
* To give background color use `backgroundColor` Default background color is `colorScheme.surfaceContainerLowest`.
381+
* To customise timeline use `timeLineBuilder`. Default text color is `colorScheme.onSurface`.
382+
* To change Hour lines color use `HourIndicatorSettings`.
383+
* To style hours, half hours & quarter hours use `HourIndicatorSettings`. Default color used is `surfaceContainerHighest`
384+
385+
```dart
386+
hourIndicatorSettings: HourIndicatorSettings(
387+
color: Colors.greenAccent,
388+
lineStyle: LineStyle.dashed,
389+
),
390+
showHalfHours: true,
391+
halfHourIndicatorSettings: HourIndicatorSettings(
392+
color: Colors.redAccent,
393+
lineStyle: LineStyle.dashed,
394+
),
395+
```
396+
357397
## Main Contributors
358398

359399
<table>

doc/theme_guide.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
## **Customise theme**
2+
The default theme supports dark mode. Refer this colors to override it.
3+
4+
| Name | Parameter | Default color |
5+
|-----------------------------------------------|------------------------|-------------------------------------|
6+
| `MonthView` Border color | Color? borderColor | colorScheme.surfaceContainerHigh |
7+
| `WeekView` Background color of week view page | Color? backgroundColor | colorScheme.surfaceContainerLowest |
8+
| `DayView` Default background color | Color? backgroundColor | colorScheme.surfaceContainerLow |
9+
| `FilledCell` Dates in month cell color | Color? backgroundColor | colorScheme.surfaceContainerLowest |
10+
| `FilledCell` Dates not in month cell color | Color? backgroundColor | colorScheme.surfaceContainerLow |
11+
| `WeekDayTile` Border color | Color? borderColor | colorScheme.secondaryContainer |
12+
| `WeekDayTile` Background color | Color? backgroundColor | colorScheme.surfaceContainerHigh |
13+
| `WeekDayTile` Text style color | NA | colorScheme.onSecondaryContainer |
14+
15+
To customise `MonthView`, `DayView` & `WeekView` page header use `HeaderStyle`.
16+
17+
```dart
18+
headerStyle: HeaderStyle(
19+
leftIconConfig: IconDataConfig(color: Colors.red),
20+
rightIconConfig: IconDataConfig(color: Colors.red),
21+
decoration: BoxDecoration(
22+
color: Theme.of(context).highlightColor,
23+
),
24+
),
25+
```
26+
27+
### Day view
28+
* Default timeline text color is `colorScheme.onSurface`.
29+
* Default hour, half hour & quarter color is `colorScheme.surfaceContainerHighest`.
30+
* Default timeline color `colorScheme.primaryColorLight`.
31+
32+
Default hour indicator settings.
33+
```dart
34+
HourIndicatorSettings(
35+
height: widget.heightPerMinute,
36+
// Color of horizontal and vertical lines
37+
color: Theme.of(context).colorScheme.surfaceContainerHighest,
38+
offset: 5,
39+
);
40+
```
41+
42+
### Week view
43+
* Week-number text color - Default color `onSecondaryContainer`.
44+
* To customise week number & weekdays use `weekNumberBuilder` & `weekDayBuilder`.
45+
* Default week tile color is `colorScheme.surfaceContainerHigh`.
46+
* To give background color use `backgroundColor` Default background color is `colorScheme.surfaceContainerLowest`.
47+
* To customise timeline use `timeLineBuilder`. Default text color is `colorScheme.onSurface`.
48+
* To change Hour lines color use `HourIndicatorSettings`.
49+
* To style hours, half hours & quarter hours use `HourIndicatorSettings`. Default color used is `surfaceContainerHighest`
50+
51+
```dart
52+
hourIndicatorSettings: HourIndicatorSettings(
53+
color: Colors.greenAccent,
54+
lineStyle: LineStyle.dashed,
55+
),
56+
showHalfHours: true,
57+
halfHourIndicatorSettings: HourIndicatorSettings(
58+
color: Colors.redAccent,
59+
lineStyle: LineStyle.dashed,
60+
),
61+
```

example/lib/main.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:ui';
22

33
import 'package:calendar_view/calendar_view.dart';
4+
import 'package:example/theme/app_theme.dart';
45
import 'package:flutter/material.dart';
56

67
import 'pages/home_page.dart';
@@ -11,7 +12,14 @@ void main() {
1112
runApp(MyApp());
1213
}
1314

14-
class MyApp extends StatelessWidget {
15+
class MyApp extends StatefulWidget {
16+
@override
17+
State<MyApp> createState() => _MyAppState();
18+
}
19+
20+
class _MyAppState extends State<MyApp> {
21+
bool isDarkMode = false;
22+
1523
// This widget is the root of your application.
1624
@override
1725
Widget build(BuildContext context) {
@@ -20,15 +28,19 @@ class MyApp extends StatelessWidget {
2028
child: MaterialApp(
2129
title: 'Flutter Calendar Page Demo',
2230
debugShowCheckedModeBanner: false,
23-
theme: ThemeData.light(),
31+
theme: AppTheme.lightTheme,
32+
darkTheme: AppTheme.darkTheme,
33+
themeMode: isDarkMode ? ThemeMode.dark : ThemeMode.light,
2434
scrollBehavior: ScrollBehavior().copyWith(
2535
dragDevices: {
2636
PointerDeviceKind.trackpad,
2737
PointerDeviceKind.mouse,
2838
PointerDeviceKind.touch,
2939
},
3040
),
31-
home: HomePage(),
41+
home: HomePage(
42+
onChangeTheme: (isDark) => setState(() => isDarkMode = isDark),
43+
),
3244
),
3345
);
3446
}

example/lib/pages/create_event_page.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:calendar_view/calendar_view.dart';
22
import 'package:flutter/material.dart';
33

4-
import '../app_colors.dart';
54
import '../extension.dart';
65
import '../widgets/add_event_form.dart';
76

@@ -12,22 +11,24 @@ class CreateEventPage extends StatelessWidget {
1211

1312
@override
1413
Widget build(BuildContext context) {
14+
final color = Theme.of(context).colorScheme;
15+
1516
return Scaffold(
1617
appBar: AppBar(
1718
elevation: 0,
18-
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
19+
backgroundColor: color.surfaceContainerHigh,
1920
centerTitle: false,
2021
leading: IconButton(
2122
onPressed: context.pop,
2223
icon: Icon(
2324
Icons.arrow_back,
24-
color: AppColors.black,
25+
color: color.onSurface,
2526
),
2627
),
2728
title: Text(
2829
event == null ? "Create New Event" : "Update Event",
2930
style: TextStyle(
30-
color: AppColors.black,
31+
color: color.onSurface,
3132
fontSize: 20.0,
3233
fontWeight: FontWeight.bold,
3334
),

example/lib/pages/day_view_page.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class _DayViewPageDemoState extends State<DayViewPageDemo> {
2222
selectedView: CalendarView.day,
2323
),
2424
mobileWidget: Scaffold(
25+
primary: false,
26+
appBar: AppBar(
27+
leading: const SizedBox.shrink(),
28+
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
29+
),
2530
floatingActionButton: FloatingActionButton(
2631
child: Icon(Icons.add),
2732
elevation: 8,

example/lib/pages/event_details_page.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,23 @@ class DetailsPage extends StatelessWidget {
9090
children: [
9191
Expanded(
9292
child: ElevatedButton(
93+
child: Text('Delete Event'),
94+
style: ElevatedButton.styleFrom(
95+
backgroundColor:
96+
Theme.of(context).colorScheme.surfaceContainer,
97+
),
9398
onPressed: () {
9499
CalendarControllerProvider.of(context)
95100
.controller
96101
.remove(event);
97102
Navigator.of(context).pop();
98103
},
99-
child: Text('Delete Event'),
100104
),
101105
),
102106
SizedBox(width: 30),
103107
Expanded(
104108
child: ElevatedButton(
109+
child: Text('Edit Event'),
105110
onPressed: () async {
106111
final result = await Navigator.of(context).push(
107112
MaterialPageRoute(
@@ -115,7 +120,10 @@ class DetailsPage extends StatelessWidget {
115120
Navigator.of(context).pop();
116121
}
117122
},
118-
child: Text('Edit Event'),
123+
style: ElevatedButton.styleFrom(
124+
backgroundColor:
125+
Theme.of(context).colorScheme.surfaceContainer,
126+
),
119127
),
120128
),
121129
],

example/lib/pages/home_page.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ import 'mobile/mobile_home_page.dart';
55
import 'web/web_home_page.dart';
66

77
class HomePage extends StatelessWidget {
8-
const HomePage({super.key});
8+
const HomePage({
9+
this.onChangeTheme,
10+
super.key,
11+
});
12+
13+
/// Return true for dark mode
14+
/// false for light mode
15+
final void Function(bool)? onChangeTheme;
916

1017
@override
1118
Widget build(BuildContext context) {
1219
return ResponsiveWidget(
13-
mobileWidget: MobileHomePage(),
14-
webWidget: WebHomePage(),
20+
mobileWidget: MobileHomePage(onChangeTheme: onChangeTheme),
21+
webWidget: WebHomePage(onThemeChange: onChangeTheme),
1522
);
1623
}
1724
}

example/lib/pages/mobile/mobile_home_page.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@ import '../day_view_page.dart';
55
import '../month_view_page.dart';
66
import '../week_view_page.dart';
77

8-
class MobileHomePage extends StatelessWidget {
8+
class MobileHomePage extends StatefulWidget {
9+
MobileHomePage({
10+
this.onChangeTheme,
11+
super.key,
12+
});
13+
14+
final void Function(bool)? onChangeTheme;
15+
16+
@override
17+
State<MobileHomePage> createState() => _MobileHomePageState();
18+
}
19+
20+
class _MobileHomePageState extends State<MobileHomePage> {
21+
bool isDarkMode = false;
22+
923
@override
1024
Widget build(BuildContext context) {
1125
return Scaffold(
@@ -38,6 +52,15 @@ class MobileHomePage extends StatelessWidget {
3852
],
3953
),
4054
),
55+
floatingActionButton: FloatingActionButton(
56+
child: Icon(Icons.dark_mode),
57+
onPressed: () {
58+
isDarkMode = !isDarkMode;
59+
if (widget.onChangeTheme != null) {
60+
widget.onChangeTheme!(isDarkMode);
61+
}
62+
setState(() {});
63+
}),
4164
);
4265
}
4366
}

example/lib/pages/month_view_page.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class _MonthViewPageDemoState extends State<MonthViewPageDemo> {
2424
selectedView: CalendarView.month,
2525
),
2626
mobileWidget: Scaffold(
27+
primary: false,
28+
appBar: AppBar(
29+
leading: const SizedBox.shrink(),
30+
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
31+
),
2732
floatingActionButton: FloatingActionButton(
2833
child: Icon(Icons.add),
2934
elevation: 8,

0 commit comments

Comments
 (0)