Skip to content

Commit c21f0f6

Browse files
feat:✨ Add theme support for multi day view
1 parent ddae87c commit c21f0f6

File tree

13 files changed

+271
-61
lines changed

13 files changed

+271
-61
lines changed

example/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class _MyAppState extends State<MyApp> {
3434
as DayViewTheme,
3535
weekViewTheme:
3636
isDarkMode ? WeekViewTheme.dark() : WeekViewTheme.light(),
37+
multiDayViewTheme:
38+
isDarkMode ? MultiDayViewTheme.dark() : MultiDayViewTheme.light(),
3739
),
3840
child: CalendarControllerProvider(
3941
controller: EventController()..addAll(_events),

example/lib/theme/app_theme.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ class AppTheme {
5050
// Light colors
5151
static final _dayViewTheme = DayViewTheme.light();
5252
static final _weekViewTheme = WeekViewTheme.light();
53+
static final _multiDayViewTheme = MultiDayViewTheme.light();
5354

5455
// Dark colors
5556
static final _appDarkTheme = AppThemeExtension.dark();
5657
static final _monthViewDarkTheme = MonthViewTheme.dark();
5758
static final _dayViewDarkTheme = DayViewTheme.dark();
5859
static final _weekViewDarkTheme = WeekViewTheme.dark();
60+
static final _multiDayViewDarkTheme = MultiDayViewTheme.dark();
5961

6062
// Light theme
6163
static final light = ThemeData.light().copyWith(
@@ -81,6 +83,7 @@ class AppTheme {
8183
extensions: [
8284
_dayViewTheme,
8385
_weekViewTheme,
86+
_multiDayViewTheme,
8487
],
8588
);
8689

@@ -130,6 +133,7 @@ class AppTheme {
130133
_monthViewDarkTheme,
131134
_dayViewDarkTheme,
132135
_weekViewDarkTheme,
136+
_multiDayViewDarkTheme,
133137
],
134138
);
135139
}

example/lib/widgets/add_event_form.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
103103
Text(
104104
'Recurring Event',
105105
style: TextStyle(
106-
color: AppColors.black,
106+
color: color.surface,
107107
fontSize: 16,
108108
),
109109
),
@@ -128,7 +128,7 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
128128
}
129129
});
130130
},
131-
activeColor: Colors.blue,
131+
activeColor: color.surface,
132132
),
133133
],
134134
),
@@ -205,10 +205,10 @@ class _AddOrEditEventFormState extends State<AddOrEditEventForm> {
205205
updateWeekdaysSelection();
206206
}
207207

208-
if (mounted) {
209-
setState(() {});
210-
}
211-
},
208+
if (mounted) {
209+
setState(() {});
210+
}
211+
},
212212
validator: (value) {
213213
if (value == null || value == "") {
214214
return "Please select end date.";

lib/calendar_view.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export './src/theme/calendar_theme.dart';
2121
export './src/theme/day_view_theme.dart';
2222
export './src/theme/month_view_theme.dart';
2323
export './src/theme/week_view_theme.dart';
24+
export './src/theme/multi_day_view_theme.dart';
2425
export './src/typedefs.dart';
2526
export './src/week_view/week_view.dart';
2627
export './src/multi_day_view/multi_day_view.dart';

lib/src/components/headers/month_page_header.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class MonthPageHeader extends CalendarPageHeader {
2222
Color backgroundColor = Constants.headerBackground,
2323
StringProvider? dateStringBuilder,
2424
required DateTime date,
25-
HeaderStyle headerStyle =
26-
const HeaderStyle(),
25+
HeaderStyle headerStyle = const HeaderStyle(),
2726
}) : super(
2827
key: key,
2928
date: date,

lib/src/day_view/day_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
662662
/// Default timeline builder this builder will be used if
663663
/// [widget.eventTileBuilder] is null
664664
///
665-
Widget _defaultTimeLineBuilder(date) => DefaultTimeLineMark(
665+
Widget _defaultTimeLineBuilder(DateTime date) => DefaultTimeLineMark(
666666
date: date,
667667
timeStringBuilder: widget.timeStringBuilder,
668668
markingStyle: TextStyle(

lib/src/extensions.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,23 @@ extension BuildContextExtension on BuildContext {
327327

328328
WeekViewTheme get weekViewColors =>
329329
Theme.of(this).extension<WeekViewTheme>() ?? WeekViewTheme.light();
330+
331+
MultiDayViewTheme get multiDayViewColors =>
332+
Theme.of(this).extension<MultiDayViewTheme>() ??
333+
MultiDayViewTheme.light();
334+
}
335+
336+
extension BuildContextMultiDayViewThemeExtension on BuildContext {
337+
/// Get MultiDayViewTheme from Theme
338+
MultiDayViewTheme get multiDayViewTheme {
339+
final theme = Theme.of(this).extension<MultiDayViewTheme>();
340+
if (theme != null) {
341+
return theme;
342+
}
343+
344+
// If no theme extension is available, return based on brightness
345+
return Theme.of(this).brightness == Brightness.dark
346+
? MultiDayViewTheme.dark()
347+
: MultiDayViewTheme.light();
348+
}
330349
}

lib/src/modals.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class LiveTimeIndicatorSettings {
5353
/// Flag to show time on live time line.
5454
final bool showTime;
5555

56-
/// Flag to show time backgroud view.
56+
/// Flag to show time background view.
5757
final bool showTimeBackgroundView;
5858

5959
/// Radius of bullet.

lib/src/multi_day_view/_internal_multi_day_view_page.dart

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import '../components/week_view_components.dart';
1010
import '../enumerations.dart';
1111
import '../event_arrangers/event_arrangers.dart';
1212
import '../event_controller.dart';
13+
import '../extensions.dart';
1314
import '../modals.dart';
1415
import '../painters.dart';
1516
import '../typedefs.dart';
@@ -140,7 +141,7 @@ class InternalMultiDayViewPage<T extends Object?> extends StatefulWidget {
140141
final bool showQuarterHours;
141142

142143
/// Display workday bottom line
143-
final bool showWeekDayBottomLine;
144+
final bool showMutliDayBottomLine;
144145

145146
/// Emulate vertical line offset from hour line starts.
146147
final double emulateVerticalOffsetBy;
@@ -219,7 +220,7 @@ class InternalMultiDayViewPage<T extends Object?> extends StatefulWidget {
219220
required this.multiDayViewScrollController,
220221
this.lastScrollOffset = 0.0,
221222
this.keepScrollOffset = false,
222-
this.showWeekDayBottomLine = true})
223+
this.showMutliDayBottomLine = true})
223224
: super(key: key);
224225

225226
@override
@@ -255,6 +256,8 @@ class _InternalMultiDayViewPageState<T extends Object?>
255256
@override
256257
Widget build(BuildContext context) {
257258
final filteredDates = _filteredDate();
259+
final themeColor = context.multiDayViewTheme;
260+
258261
return Container(
259262
height: widget.height + widget.weekTitleHeight,
260263
width: widget.width,
@@ -264,18 +267,8 @@ class _InternalMultiDayViewPageState<T extends Object?>
264267
: VerticalDirection.down,
265268
crossAxisAlignment: CrossAxisAlignment.end,
266269
children: [
267-
Container(
268-
decoration: BoxDecoration(
269-
color: Colors.white,
270-
boxShadow: [
271-
BoxShadow(
272-
color: Color(0x0C000000),
273-
offset: Offset(0, 2),
274-
blurRadius: 12,
275-
spreadRadius: 0,
276-
),
277-
],
278-
),
270+
ColoredBox(
271+
color: themeColor.headerBackgroundColor,
279272
child: SizedBox(
280273
width: widget.width,
281274
child: Row(
@@ -301,18 +294,19 @@ class _InternalMultiDayViewPageState<T extends Object?>
301294
),
302295
),
303296
),
304-
if (widget.showWeekDayBottomLine)
297+
if (widget.showMutliDayBottomLine)
305298
Divider(
306299
thickness: 1,
307300
height: 1,
301+
color: themeColor.borderColor,
308302
),
309303
SizedBox(
310304
width: widget.width,
311305
child: Container(
312306
decoration: BoxDecoration(
313307
border: Border(
314308
bottom: BorderSide(
315-
color: widget.hourIndicatorSettings.color,
309+
color: themeColor.borderColor,
316310
width: 2,
317311
),
318312
),
@@ -374,7 +368,7 @@ class _InternalMultiDayViewPageState<T extends Object?>
374368
CustomPaint(
375369
size: Size(widget.width, widget.height),
376370
painter: widget.hourLinePainter(
377-
widget.hourIndicatorSettings.color,
371+
themeColor.hourLineColor,
378372
widget.hourIndicatorSettings.height,
379373
widget.timeLineWidth +
380374
widget.hourIndicatorSettings.offset,
@@ -393,7 +387,7 @@ class _InternalMultiDayViewPageState<T extends Object?>
393387
CustomPaint(
394388
size: Size(widget.width, widget.height),
395389
painter: HalfHourLinePainter(
396-
lineColor: widget.halfHourIndicatorSettings.color,
390+
lineColor: themeColor.halfHourLineColor,
397391
lineHeight: widget.halfHourIndicatorSettings.height,
398392
offset: widget.timeLineWidth +
399393
widget.halfHourIndicatorSettings.offset,
@@ -410,7 +404,7 @@ class _InternalMultiDayViewPageState<T extends Object?>
410404
CustomPaint(
411405
size: Size(widget.width, widget.height),
412406
painter: QuarterHourLinePainter(
413-
lineColor: widget.quarterHourIndicatorSettings.color,
407+
lineColor: themeColor.quarterHourLineColor,
414408
lineHeight:
415409
widget.quarterHourIndicatorSettings.height,
416410
offset: widget.timeLineWidth +
@@ -438,8 +432,8 @@ class _InternalMultiDayViewPageState<T extends Object?>
438432
? BoxDecoration(
439433
border: Border(
440434
right: BorderSide(
441-
color: widget
442-
.hourIndicatorSettings.color,
435+
color:
436+
themeColor.verticalLinesColor,
443437
width: widget
444438
.hourIndicatorSettings.height,
445439
),
@@ -524,8 +518,13 @@ class _InternalMultiDayViewPageState<T extends Object?>
524518
widget.liveTimeIndicatorSettings.height > 0 &&
525519
!widget.liveTimeIndicatorSettings.onlyShowToday)
526520
LiveTimeIndicator(
527-
liveTimeIndicatorSettings:
528-
widget.liveTimeIndicatorSettings,
521+
liveTimeIndicatorSettings: LiveTimeIndicatorSettings(
522+
color: themeColor.liveIndicatorColor,
523+
height: widget.liveTimeIndicatorSettings.height,
524+
offset: widget.liveTimeIndicatorSettings.offset,
525+
onlyShowToday:
526+
widget.liveTimeIndicatorSettings.onlyShowToday,
527+
),
529528
width: widget.width,
530529
height: widget.height,
531530
heightPerMinute: widget.heightPerMinute,

0 commit comments

Comments
 (0)