Skip to content

Commit 78dc058

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

27 files changed

+408
-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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,68 @@ WeekView(
354354

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

357+
## **Customise theme**
358+
The default theme supports dark mode. Refer this colors to override it.
359+
360+
| Name | Parameter | Default color |
361+
|-----------------------------------------------|------------------------|-------------------------------------|
362+
| `MonthView` Border color | Color? borderColor | colorScheme.surfaceContainerHigh |
363+
| `WeekView` Background color of week view page | Color? backgroundColor | colorScheme.surfaceContainerLowest |
364+
| `DayView` Default background color | Color? backgroundColor | colorScheme.surfaceContainerLow |
365+
| `FilledCell` Dates in month cell color | Color? backgroundColor | colorScheme.surfaceContainerLowest |
366+
| `FilledCell` Dates not in month cell color | Color? backgroundColor | colorScheme.surfaceContainerLow |
367+
| `WeekDayTile` Border color | Color? borderColor | colorScheme.secondaryContainer |
368+
| `WeekDayTile` Background color | Color? backgroundColor | colorScheme.surfaceContainerHigh |
369+
| `WeekDayTile` Text style color | NA | colorScheme.onSecondaryContainer |
370+
371+
To customise `MonthView`, `DayView` & `WeekView` page header use `HeaderStyle`.
372+
373+
```dart
374+
headerStyle: HeaderStyle(
375+
leftIconConfig: IconDataConfig(color: Colors.red),
376+
rightIconConfig: IconDataConfig(color: Colors.red),
377+
decoration: BoxDecoration(
378+
color: Theme.of(context).highlightColor,
379+
),
380+
),
381+
```
382+
383+
### Day view
384+
* Default timeline text color is `colorScheme.onSurface`.
385+
* Default hour, half hour & quarter color is `colorScheme.surfaceContainerHighest`.
386+
* Default timeline color `colorScheme.primaryColorLight`.
387+
388+
Default hour indicator settings.
389+
```dart
390+
HourIndicatorSettings(
391+
height: widget.heightPerMinute,
392+
// Color of horizontal and vertical lines
393+
color: Theme.of(context).colorScheme.surfaceContainerHighest,
394+
offset: 5,
395+
);
396+
```
397+
398+
### Week view
399+
* Week-number text color - Default color `onSecondaryContainer`.
400+
* To customise week number & weekdays use `weekNumberBuilder` & `weekDayBuilder`.
401+
* Default week tile color is `colorScheme.surfaceContainerHigh`.
402+
* To give background color use `backgroundColor` Default background color is `colorScheme.surfaceContainerLowest`.
403+
* To customise timeline use `timeLineBuilder`. Default text color is `colorScheme.onSurface`.
404+
* To change Hour lines color use `HourIndicatorSettings`.
405+
* To style hours, half hours & quarter hours use `HourIndicatorSettings`. Default color used is `surfaceContainerHighest`
406+
407+
```dart
408+
hourIndicatorSettings: HourIndicatorSettings(
409+
color: Colors.greenAccent,
410+
lineStyle: LineStyle.dashed,
411+
),
412+
showHalfHours: true,
413+
halfHourIndicatorSettings: HourIndicatorSettings(
414+
color: Colors.redAccent,
415+
lineStyle: LineStyle.dashed,
416+
),
417+
```
418+
357419
## Main Contributors
358420

359421
<table>

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,

example/lib/pages/web/web_home_page.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import '../../widgets/calendar_views.dart';
77
class WebHomePage extends StatefulWidget {
88
WebHomePage({
99
this.selectedView = CalendarView.month,
10+
this.onThemeChange,
1011
});
1112

1213
final CalendarView selectedView;
14+
final void Function(bool)? onThemeChange;
1315

1416
@override
1517
_WebHomePageState createState() => _WebHomePageState();
@@ -35,6 +37,7 @@ class _WebHomePageState extends State<WebHomePage> {
3537
child: CalendarConfig(
3638
onViewChange: _setView,
3739
currentView: _selectedView,
40+
onThemeChange: widget.onThemeChange,
3841
),
3942
),
4043
Expanded(

0 commit comments

Comments
 (0)