Skip to content

Commit 0556458

Browse files
author
Shubham Jitiya
committed
🚧 Refactor file names & color name
1 parent 420ed38 commit 0556458

File tree

8 files changed

+63
-46
lines changed

8 files changed

+63
-46
lines changed

example/lib/theme/app_theme.dart

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,34 @@ class AppTheme {
4848

4949
// Light theme
5050
static final light = CalendarTheme.light.copyWith(
51-
// TODO(Shubham): Reorder
52-
elevatedButtonTheme: ElevatedButtonThemeData(
53-
style: ElevatedButton.styleFrom(
51+
// TODO(Shubham): Reorder
52+
elevatedButtonTheme: ElevatedButtonThemeData(
53+
style: ElevatedButton.styleFrom(
54+
backgroundColor: AppColors.primary,
55+
foregroundColor: AppColors.onPrimary,
56+
),
57+
),
58+
floatingActionButtonTheme: FloatingActionButtonThemeData(
59+
backgroundColor: AppColors.primary,
60+
),
61+
inputDecorationTheme: baseInputDecorationTheme,
62+
appBarTheme: AppBarTheme(
5463
backgroundColor: AppColors.primary,
5564
foregroundColor: AppColors.onPrimary,
5665
),
57-
),
58-
floatingActionButtonTheme: FloatingActionButtonThemeData(
59-
backgroundColor: AppColors.primary,
60-
),
61-
inputDecorationTheme: baseInputDecorationTheme,
62-
appBarTheme: AppBarTheme(
63-
backgroundColor: AppColors.primary,
64-
foregroundColor: AppColors.onPrimary,
65-
),
66-
radioTheme: RadioThemeData(
67-
fillColor: WidgetStateColor.resolveWith(
68-
(_) => AppColors.primary,
66+
radioTheme: RadioThemeData(
67+
fillColor: WidgetStateColor.resolveWith(
68+
(_) => AppColors.primary,
69+
),
6970
),
70-
),
71-
);
71+
extensions: [_lightAppColors]);
72+
73+
static final _lightAppColors = CalendarThemeExtension().copyWith(
74+
// daysInMonth: Colors.green,
75+
// daysNotInMonth: Colors.orange,
76+
// pageBackground: Colors.black26,
77+
// background: Colors.red,
78+
);
7279

7380
// Dark theme
7481
static final dark = CalendarTheme.dark.copyWith(

lib/calendar_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export './src/extensions.dart';
1616
export './src/modals.dart';
1717
export './src/month_view/month_view.dart';
1818
export './src/style/header_style.dart';
19-
export './src/theme/app_colors_extension.dart'; // TODO(Shubham): Check if it is required
2019
export './src/theme/calendar_theme.dart';
20+
export './src/theme/calendar_theme_extension.dart'; // TODO(Shubham): Check if it is required
2121
export './src/typedefs.dart';
2222
export './src/week_view/week_view.dart';

lib/src/day_view/day_view.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
432432
@override
433433
Widget build(BuildContext context) {
434434
final color = Theme.of(context).colorScheme;
435+
final themeColor = context.themeColor;
435436

436437
return SafeAreaWrapper(
437438
option: widget.safeAreaOption,
@@ -448,7 +449,7 @@ class DayViewState<T extends Object?> extends State<DayView<T>> {
448449
Expanded(
449450
child: DecoratedBox(
450451
decoration: BoxDecoration(
451-
color: widget.backgroundColor ?? color.surfaceContainerLow,
452+
color: widget.backgroundColor ?? themeColor.pageBackground,
452453
),
453454
child: SizedBox(
454455
height: _height,

lib/src/extensions.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ void debugLog(String message) {
255255

256256
extension BuildContextExtension on BuildContext {
257257
// TODO(Shubham): Update here theme based if possible
258-
AppColorsExtension get themeColor =>
259-
Theme.of(this).extension<AppColorsExtension>() ?? AppColorsExtension();
258+
CalendarThemeExtension get themeColor =>
259+
Theme.of(this).extension<CalendarThemeExtension>() ??
260+
CalendarThemeExtension();
260261
}

lib/src/month_view/month_view.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,8 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
569569
return FilledCell<T>(
570570
date: date,
571571
shouldHighlight: isToday,
572-
backgroundColor: isInMonth
573-
? themeColor.surfaceContainerLowest
574-
: themeColor.surfaceContainerLow,
572+
backgroundColor:
573+
isInMonth ? themeColor.daysInMonth : themeColor.daysNotInMonth,
575574
events: events,
576575
isInMonth: isInMonth,
577576
onTileTap: widget.onEventTap,
@@ -585,9 +584,8 @@ class MonthViewState<T extends Object?> extends State<MonthView<T>> {
585584
return FilledCell<T>(
586585
date: date,
587586
shouldHighlight: isToday,
588-
backgroundColor: isInMonth
589-
? themeColor.surfaceContainerLowest
590-
: themeColor.surfaceContainerLow,
587+
backgroundColor:
588+
isInMonth ? themeColor.daysInMonth : themeColor.daysNotInMonth,
591589
events: events,
592590
onTileTap: widget.onEventTap,
593591
onTileLongTap: widget.onEventLongTap,

lib/src/theme/calendar_theme.dart

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

3-
import 'app_colors_extension.dart';
3+
import 'calendar_theme_extension.dart';
44
import 'dark_app_colors.dart';
55

66
class CalendarTheme {
@@ -12,15 +12,15 @@ class CalendarTheme {
1212
);
1313

1414
// Default colors assigned are of light theme
15-
static final _lightAppColors = AppColorsExtension();
15+
static final _lightAppColors = CalendarThemeExtension();
1616

1717
// TODO(Shubham): Setup dark colors
1818
// Dark theme
1919
static final dark = ThemeData.dark().copyWith(
2020
extensions: [_darkAppColors],
2121
);
2222

23-
static final _darkAppColors = AppColorsExtension(
23+
static final _darkAppColors = CalendarThemeExtension(
2424
primary: DarkAppColors.primary,
2525
onPrimary: DarkAppColors.onPrimary,
2626
onPrimaryContainer: DarkAppColors.onPrimaryContainer,
@@ -29,7 +29,8 @@ class CalendarTheme {
2929
secondaryContainer: DarkAppColors.secondaryContainer,
3030
outlineVariant: DarkAppColors.outlineVariant,
3131
onSurface: DarkAppColors.onSurface,
32-
surfaceContainerLowest: DarkAppColors.surfaceContainerLowest,
33-
surfaceContainerLow: DarkAppColors.surfaceContainerLow,
32+
daysInMonth: DarkAppColors.surfaceContainerLowest,
33+
daysNotInMonth: DarkAppColors.surfaceContainerLow,
34+
pageBackground: DarkAppColors.surfaceContainerLowest,
3435
);
3536
}

lib/src/theme/app_colors_extension.dart renamed to lib/src/theme/calendar_theme_extension.dart

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import 'package:flutter/material.dart';
33
import 'light_app_colors.dart';
44

55
// Default theme is light theme
6-
class AppColorsExtension extends ThemeExtension<AppColorsExtension> {
7-
AppColorsExtension({
6+
class CalendarThemeExtension extends ThemeExtension<CalendarThemeExtension> {
7+
CalendarThemeExtension({
88
this.primary = LightAppColors.primary,
99
this.onPrimary = LightAppColors.onPrimary,
1010
this.onPrimaryContainer = LightAppColors.onPrimaryContainer,
@@ -13,8 +13,9 @@ class AppColorsExtension extends ThemeExtension<AppColorsExtension> {
1313
this.secondaryContainer = LightAppColors.secondaryContainer,
1414
this.outlineVariant = LightAppColors.outlineVariant,
1515
this.onSurface = LightAppColors.onSurface,
16-
this.surfaceContainerLowest = LightAppColors.surfaceContainerLowest,
17-
this.surfaceContainerLow = LightAppColors.surfaceContainerLow,
16+
this.daysInMonth = LightAppColors.surfaceContainerLowest,
17+
this.daysNotInMonth = LightAppColors.surfaceContainerLow,
18+
this.pageBackground = LightAppColors.surfaceContainerLowest,
1819
});
1920

2021
final Color primary;
@@ -25,31 +26,39 @@ class AppColorsExtension extends ThemeExtension<AppColorsExtension> {
2526
final Color secondaryContainer;
2627
final Color outlineVariant;
2728
final Color onSurface;
28-
final Color surfaceContainerLowest;
29-
final Color surfaceContainerLow;
29+
final Color daysInMonth;
30+
final Color daysNotInMonth;
31+
32+
/// Background color of week view & day view
33+
final Color pageBackground;
3034

3135
@override
32-
ThemeExtension<AppColorsExtension> copyWith({
36+
ThemeExtension<CalendarThemeExtension> copyWith({
3337
Color? primary,
3438
Color? onPrimary,
39+
Color? daysInMonth,
40+
Color? daysNotInMonth,
41+
Color? pageBackground,
3542
Color? surfaceContainerHigh,
36-
Color? background,
3743
}) {
38-
return AppColorsExtension(
44+
return CalendarThemeExtension(
3945
primary: primary ?? this.primary,
4046
onPrimary: onPrimary ?? this.onPrimary,
4147
surfaceContainerHigh: surfaceContainerHigh ?? this.surfaceContainerHigh,
48+
daysInMonth: daysInMonth ?? this.daysInMonth,
49+
daysNotInMonth: daysNotInMonth ?? this.daysNotInMonth,
50+
pageBackground: pageBackground ?? this.pageBackground,
4251
);
4352
}
4453

4554
@override
46-
ThemeExtension<AppColorsExtension> lerp(
47-
covariant ThemeExtension<AppColorsExtension>? other,
55+
ThemeExtension<CalendarThemeExtension> lerp(
56+
covariant ThemeExtension<CalendarThemeExtension>? other,
4857
double t,
4958
) {
50-
if (other is! AppColorsExtension) return this;
59+
if (other is! CalendarThemeExtension) return this;
5160

52-
return AppColorsExtension(
61+
return CalendarThemeExtension(
5362
primary: Color.lerp(primary, other.primary, t)!,
5463
);
5564
}

lib/src/week_view/_internal_week_view_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ class _InternalWeekViewPageState<T extends Object?>
256256
final themeColor = context.themeColor;
257257

258258
return Container(
259-
color: widget.backgroundColor ?? themeColor.surfaceContainerLowest,
259+
color: widget.backgroundColor ?? themeColor.pageBackground,
260260
height: widget.height + widget.weekTitleHeight,
261261
width: widget.width,
262262
child: Column(

0 commit comments

Comments
 (0)