Skip to content

Commit

Permalink
Migrate to switch expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Jul 24, 2024
1 parent ecea0bf commit be4ee3b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 52 deletions.
40 changes: 15 additions & 25 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,36 +237,26 @@ enum PredefinedVisibleDateRange { day, threeDays, workWeek, week, fixed }

extension on PredefinedVisibleDateRange {
VisibleDateRange get visibleDateRange {
switch (this) {
case PredefinedVisibleDateRange.day:
return VisibleDateRange.days(1);
case PredefinedVisibleDateRange.threeDays:
return VisibleDateRange.days(3);
case PredefinedVisibleDateRange.workWeek:
return VisibleDateRange.weekAligned(5);
case PredefinedVisibleDateRange.week:
return VisibleDateRange.week();
case PredefinedVisibleDateRange.fixed:
return VisibleDateRange.fixed(
return switch (this) {
PredefinedVisibleDateRange.day => VisibleDateRange.days(1),
PredefinedVisibleDateRange.threeDays => VisibleDateRange.days(3),
PredefinedVisibleDateRange.workWeek => VisibleDateRange.weekAligned(5),
PredefinedVisibleDateRange.week => VisibleDateRange.week(),
PredefinedVisibleDateRange.fixed => VisibleDateRange.fixed(
DateTimeTimetable.today(),
DateTime.daysPerWeek,
);
}
),
};
}

String get title {
switch (this) {
case PredefinedVisibleDateRange.day:
return 'Day';
case PredefinedVisibleDateRange.threeDays:
return '3 Days';
case PredefinedVisibleDateRange.workWeek:
return 'Work Week';
case PredefinedVisibleDateRange.week:
return 'Week';
case PredefinedVisibleDateRange.fixed:
return '7 Days (fixed)';
}
return switch (this) {
PredefinedVisibleDateRange.day => 'Day',
PredefinedVisibleDateRange.threeDays => '3 Days',
PredefinedVisibleDateRange.workWeek => 'Work Week',
PredefinedVisibleDateRange.week => 'Week',
PredefinedVisibleDateRange.fixed => '7 Days (fixed)',
};
}
}

Expand Down
5 changes: 3 additions & 2 deletions example/lib/positioning_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ List<TimeOverlay> positioningDemoOverlayProvider(
) {
assert(date.debugCheckIsValidTimetableDate());

final widget =
ColoredBox(color: context.theme.brightness.contrastColor.withOpacity(.1));
final widget = ColoredBox(
color: context.theme.brightness.contrastColor.withOpacity(0.1),
);

if (DateTime.monday <= date.weekday && date.weekday <= DateTime.friday) {
return [
Expand Down
38 changes: 13 additions & 25 deletions lib/src/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,19 @@ class TimetableLocalizationsDelegate
bool shouldReload(TimetableLocalizationsDelegate old) => false;

static TimetableLocalizations? _getLocalization(Locale locale) {
switch (locale.languageCode) {
case 'de':
return const TimetableLocalizationDe();
case 'en':
return const TimetableLocalizationEn();
case 'es':
return const TimetableLocalizationEs();
case 'fr':
return const TimetableLocalizationFr();
case 'hu':
return const TimetableLocalizationHu();
case 'it':
return const TimetableLocalizationIt();
case 'ja':
return const TimetableLocalizationJa();
case 'pt':
return const TimetableLocalizationPt();
case 'zh':
if (locale.countryCode?.toLowerCase() == 'tw') {
return const TimetableLocalizationZhTw();
}
return const TimetableLocalizationZhCn();
default:
return null;
}
return switch ((locale.languageCode, locale.countryCode?.toUpperCase())) {
('de', _) => const TimetableLocalizationDe(),
('en', _) => const TimetableLocalizationEn(),
('es', _) => const TimetableLocalizationEs(),
('fr', _) => const TimetableLocalizationFr(),
('hu', _) => const TimetableLocalizationHu(),
('it', _) => const TimetableLocalizationIt(),
('ja', _) => const TimetableLocalizationJa(),
('pt', _) => const TimetableLocalizationPt(),
('zh', 'TW') => const TimetableLocalizationZhTw(),
('zh', _) => const TimetableLocalizationZhCn(),
_ => null,
};
}
}

Expand Down

0 comments on commit be4ee3b

Please sign in to comment.