Skip to content

Commit

Permalink
refactor: relax null checks !. and prefer ?. (#34)
Browse files Browse the repository at this point in the history
* refactor: relax null checks `!.` and prefer `?.`

* refactor: further relax null checks `!.` and prefer `?.`
  • Loading branch information
albertms10 committed Dec 19, 2021
1 parent b79be05 commit d370609
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 28 deletions.
14 changes: 7 additions & 7 deletions lib/src/model/booking/booking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class Booking extends Item {
Map<String, dynamic> toJson() => {
...super.toJson(),
_JsonFields.description: description,
_JsonFields.date: date!.toIso8601String().split('T').first,
_JsonFields.startTime: startTime!.format24Hour(),
_JsonFields.endTime: endTime!.format24Hour(),
_JsonFields.date: date?.toIso8601String().split('T').first,
_JsonFields.startTime: startTime?.format24Hour(),
_JsonFields.endTime: endTime?.format24Hour(),
_JsonFields.status: status.index,
_JsonFields.isLocked: isLocked,
};
Expand All @@ -73,12 +73,12 @@ class Booking extends Item {
Map<TimeOfDay, Duration> get hoursSpan {
final timeRanges = <TimeOfDay, Duration>{};

var runTime = startTime;
var runTime = startTime!;
var runDuration = Duration.zero;

while (runDuration < duration) {
final nextHour = TimeOfDay(
hour: (runTime!.hour + 1) % TimeOfDay.hoursPerDay,
hour: (runTime.hour + 1) % TimeOfDay.hoursPerDay,
minute: 0,
);

Expand All @@ -98,8 +98,8 @@ class Booking extends Item {
return timeRanges;
}

String get timeRange => '${startTime!.format24Hour()}'
'–${endTime!.format24Hour()}';
String get timeRange => '${startTime?.format24Hour()}'
'–${endTime?.format24Hour()}';

String get dateTimeRange => '${DateFormat.yMd().format(date!)} $timeRange';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/booking/recurring_booking.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class RecurringBooking extends Booking {
_JsonFields.repeatEvery: repeatEvery,
if (method == RecurringBookingMethod.endDate)
_JsonFields.recurringEndDate:
_recurringEndDate!.toIso8601String().split('T').first
_recurringEndDate?.toIso8601String().split('T').first
else if (method == RecurringBookingMethod.occurrences)
_JsonFields.occurrences: _occurrences,
};
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/date/date_range.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class DateRange extends Item {
@override
Map<String, dynamic> toJson() => {
...super.toJson(),
_JsonFields.startDate: startDate!.toIso8601String().split('T').first,
_JsonFields.endDate: endDate!.toIso8601String().split('T').first,
_JsonFields.startDate: startDate?.toIso8601String().split('T').first,
_JsonFields.endDate: endDate?.toIso8601String().split('T').first,
};

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class Item implements Comparable<Item>, Serializable {
_JsonFields.creationDateTime: creationDateTime.toIso8601String(),
if (modificationDateTime != null)
_JsonFields.modificationDateTime:
modificationDateTime!.toIso8601String(),
modificationDateTime?.toIso8601String(),
_JsonFields.modificationCount: modificationCount,
};

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/booking/booking_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class _BookingCardInfo extends StatelessWidget {
if (constraints.maxHeight > 30.0)
Text(
booking.timeRange,
style: theme.textTheme.caption!.copyWith(
style: theme.textTheme.caption?.copyWith(
fontSize: constraints.maxHeight > 40.0
? 14.0
: constraints.maxHeight * 0.4,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/cabin/cabin_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CabinIcon extends StatelessWidget {

final text = Text(
'$number',
style: theme.textTheme.headline5!.copyWith(
style: theme.textTheme.headline5?.copyWith(
color: shouldShowProgress
? theme.colorScheme.secondary
: theme.colorScheme.onSecondary,
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/item/activity_line_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class ActivityLineChart extends StatelessWidget {
width: 250.0,
padding: const EdgeInsets.symmetric(vertical: 24.0),
child: DetailLineChart(
minX: dateRange.startDate!.toDouble(),
maxX: dateRange.endDate!.toDouble(),
minX: dateRange.startDate?.toDouble(),
maxX: dateRange.endDate?.toDouble(),
spots: [
for (final entry in occupiedDurationPerWeek.entries)
FlSpot(
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/layout/centered_icon_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class CenteredIconMessage extends StatelessWidget {
message!,
style: Theme.of(context)
.textTheme
.headline5!
.copyWith(color: Colors.grey[600]),
.headline5
?.copyWith(color: Colors.grey[600]),
),
if (icon != null || message != null) const SizedBox(height: 82.0),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/layout/day_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _WeekDateTime extends StatelessWidget {
),
Text(
DateFormat.yMMMMd().format(dateTime),
style: theme.textTheme.subtitle2!.copyWith(color: theme.hintColor),
style: theme.textTheme.subtitle2?.copyWith(color: theme.hintColor),
),
],
);
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/layout/heading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Heading extends StatelessWidget {
children: [
Text(
heading,
style: theme.textTheme.headline5!.copyWith(
style: theme.textTheme.headline5?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.8),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/layout/scrollable_time_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class ScrollableTimeTable extends StatelessWidget {
child: Text(
AppLocalizations.of(context)!.noCabins,
textAlign: TextAlign.center,
style: theme.textTheme.headline5!
.copyWith(color: Colors.grey[600]),
style: theme.textTheme.headline5
?.copyWith(color: Colors.grey[600]),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/layout/time_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class TimeColumn extends StatelessWidget {
alignment: Alignment.topCenter,
child: Text(
TimeOfDay(hour: hour, minute: 0).format(context),
style: theme.textTheme.headline5!
.copyWith(color: theme.hintColor),
style: theme.textTheme.headline5
?.copyWith(color: theme.hintColor),
),
),
],
Expand Down
10 changes: 5 additions & 5 deletions lib/widgets/pages/summary_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class _SummaryPageState extends State<SummaryPage>
onTap: widget.setNavigationPage == null
? null
: () {
widget.setNavigationPage!.call(AppPages.bookings);
widget.setNavigationPage?.call(AppPages.bookings);
},
items: [
StatisticItem(
Expand Down Expand Up @@ -82,7 +82,7 @@ class _SummaryPageState extends State<SummaryPage>
onTap: widget.setNavigationPage == null
? null
: () {
widget.setNavigationPage!.call(AppPages.cabins);
widget.setNavigationPage?.call(AppPages.cabins);
},
items: [
StatisticSimpleItem(
Expand All @@ -97,7 +97,7 @@ class _SummaryPageState extends State<SummaryPage>
onTap: widget.setNavigationPage == null
? null
: () {
widget.setNavigationPage!.call(AppPages.schoolYears);
widget.setNavigationPage?.call(AppPages.schoolYears);
},
items: [
StatisticSimpleItem(
Expand All @@ -120,7 +120,7 @@ class _SummaryPageState extends State<SummaryPage>
: () {
dayHandler.dateTime =
cabinManager.mostBookedDayEntry!.key;
widget.setNavigationPage!.call(AppPages.bookings);
widget.setNavigationPage?.call(AppPages.bookings);
},
items: [
StatisticSimpleItem(
Expand Down Expand Up @@ -179,7 +179,7 @@ class _SummaryPageState extends State<SummaryPage>
? null
: (dateTime, value) {
dayHandler.dateTime = dateTime;
widget.setNavigationPage!.call(AppPages.bookings);
widget.setNavigationPage?.call(AppPages.bookings);
},
legendLessLabel: appLocalizations.less,
legendMoreLabel: appLocalizations.more,
Expand Down

0 comments on commit d370609

Please sign in to comment.