Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix date chips not rendering properly #18

Merged
merged 4 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/alarm/logic/schedule_description.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:clock_app/alarm/types/range_interval.dart';
import 'package:clock_app/common/data/weekdays.dart';
import 'package:clock_app/alarm/types/alarm.dart';
import 'package:clock_app/alarm/types/schedules/daily_alarm_schedule.dart';
Expand Down Expand Up @@ -43,11 +44,11 @@
return 'Every ${weekdays.where((weekday) => alarmWeekdays.contains(weekday)).map((weekday) => weekday.displayName).join(', ')}';
case DatesAlarmSchedule:
List<DateTime> dates = alarm.dates;
return 'On ${DateFormat(dateFormat).format(dates[0])}${dates.length > 1 ? ' and ${dates.length - 1} other${dates.length > 2 ? 's' : ''}' : ''}';
return 'On ${DateFormat(dateFormat).format(dates[0])}${dates.length > 1 ? ' and ${dates.length - 1} other date${dates.length > 2 ? 's' : ''} ' : ''}';

Check warning on line 47 in lib/alarm/logic/schedule_description.dart

View check run for this annotation

Codecov / codecov/patch

lib/alarm/logic/schedule_description.dart#L47

Added line #L47 was not covered by tests
case RangeAlarmSchedule:
DateTime rangeStart = alarm.startDate;
DateTime rangeEnd = alarm.endDate;
Duration interval = alarm.interval;
RangeInterval interval = alarm.interval;

Check warning on line 51 in lib/alarm/logic/schedule_description.dart

View check run for this annotation

Codecov / codecov/patch

lib/alarm/logic/schedule_description.dart#L51

Added line #L51 was not covered by tests

String startString = DateFormat(dateFormat).format(rangeStart);
String endString = DateFormat(dateFormat).format(rangeEnd);
Expand All @@ -65,7 +66,7 @@
}
}

return '${interval.inDays == 1 ? "Daily" : "Weekly"} from $startString to $endString';
return '${interval == RangeInterval.daily ? "Daily" : "Weekly"} from $startString to $endString';

Check warning on line 69 in lib/alarm/logic/schedule_description.dart

View check run for this annotation

Codecov / codecov/patch

lib/alarm/logic/schedule_description.dart#L69

Added line #L69 was not covered by tests
default:
return 'Not scheduled';
}
Expand Down
5 changes: 3 additions & 2 deletions lib/alarm/types/alarm.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:clock_app/alarm/logic/schedule_alarm.dart';
import 'package:clock_app/alarm/types/alarm_runner.dart';
import 'package:clock_app/alarm/types/alarm_task.dart';
import 'package:clock_app/alarm/types/range_interval.dart';
import 'package:clock_app/alarm/types/schedules/alarm_schedule.dart';
import 'package:clock_app/alarm/types/schedules/daily_alarm_schedule.dart';
import 'package:clock_app/alarm/types/schedules/dates_alarm_schedule.dart';
Expand Down Expand Up @@ -261,8 +262,8 @@
return (getSetting("Date Range") as DateTimeSetting).value[1];
}

Duration get interval {
return (getSetting("Interval") as SelectSetting<Duration>).value;
RangeInterval get interval {
return (getSetting("Interval") as SelectSetting<RangeInterval>).value;

Check warning on line 266 in lib/alarm/types/alarm.dart

View check run for this annotation

Codecov / codecov/patch

lib/alarm/types/alarm.dart#L265-L266

Added lines #L265 - L266 were not covered by tests
}

Alarm.fromJson(Json json)
Expand Down
6 changes: 3 additions & 3 deletions lib/common/logic/card_decoration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ BoxDecoration getCardDecoration(BuildContext context,
strokeAlign: BorderSide.strokeAlignInside,
)
: null,
color: color ?? Theme.of(context).colorScheme.surface,
borderRadius: (Theme.of(context).cardTheme.shape as RoundedRectangleBorder)
.borderRadius,
color: color ?? colorScheme.surface,
borderRadius:
(theme.cardTheme.shape as RoundedRectangleBorder).borderRadius,
boxShadow: [
if (showShadow && (themeStyle?.shadowOpacity ?? 0) > 0)
BoxShadow(
Expand Down
22 changes: 12 additions & 10 deletions lib/common/widgets/fields/date_picker_field.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:clock_app/common/widgets/card_container.dart';
import 'package:clock_app/common/widgets/fields/date_picker_bottom_sheet.dart';
import 'package:clock_app/settings/data/settings_schema.dart';
import 'package:clock_app/settings/types/setting.dart';
Expand Down Expand Up @@ -142,17 +143,18 @@ class DateChip extends StatelessWidget {
@override
Widget build(BuildContext context) {
ColorScheme colorScheme = Theme.of(context).colorScheme;
return Chip(
backgroundColor: colorScheme.onBackground.withOpacity(0.1),
// labelPadding: EdgeInsets.zero,
padding: EdgeInsets.zero,

// side: ,
label: Text(
DateFormat(dateFormat).format(date),
style: const TextStyle(fontSize: 10),
return CardContainer(
key: const Key("DateChip"),
color: colorScheme.primary,
margin: const EdgeInsets.all(0),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
DateFormat(dateFormat).format(date),
style: const TextStyle(fontSize: 10)
.copyWith(color: colorScheme.onPrimary),
),
),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
}
}
8 changes: 5 additions & 3 deletions test/common/widgets/fields/date_picker_field_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:clock_app/common/widgets/fields/date_picker_field.dart';
import 'package:clock_app/theme/theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

Expand All @@ -17,19 +18,19 @@ void main() {
testWidgets('with 1 date', (tester) async {
final value = [DateTime(2021, 1, 1)];
await _renderWidget(tester, value: value);
final valueFinder = find.byType(DateChip);
final valueFinder = find.byKey(const Key("DateChip"));
expect(valueFinder, findsOneWidget);
});
testWidgets('with 2 dates', (tester) async {
final value = [DateTime(2021, 1, 1), DateTime(2021, 1, 2)];
await _renderWidget(tester, value: value);
final valueFinder = find.byType(DateChip);
final valueFinder = find.byKey(const Key("DateChip"));
expect(valueFinder, findsNWidgets(2));
});
testWidgets('with 10 dates', (tester) async {
final value = List.generate(10, (index) => DateTime(2021, 1, 1));
await _renderWidget(tester, value: value);
final valueFinder = find.byType(DateChip);
final valueFinder = find.byKey(const Key("DateChip"));
expect(valueFinder, findsNWidgets(10));
});
});
Expand Down Expand Up @@ -75,6 +76,7 @@ Future<void> _renderWidget(WidgetTester tester,
void Function(List<DateTime>)? onChanged}) async {
await tester.pumpWidget(
MaterialApp(
theme: defaultTheme,
home: Scaffold(
body: DatePickerField(
value: value,
Expand Down