Skip to content

Commit

Permalink
Merge f89e3b3 into 2e2ced0
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Sep 30, 2021
2 parents 2e2ced0 + f89e3b3 commit 0dff4d6
Show file tree
Hide file tree
Showing 27 changed files with 345 additions and 166 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/flutter-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
analyze-and-test:
name: Analyze and test
runs-on: ubuntu-latest
timeout-minutes: 3
timeout-minutes: 5
if: ${{ github.event.pull_request.draft == false }}

steps:
Expand All @@ -26,7 +26,8 @@ jobs:
- run: flutter format --set-exit-if-changed .
- run: flutter analyze --fatal-infos
- run: flutter test --coverage
- name: Coveralls GitHub Action

- name: Run Coveralls
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -67,7 +68,7 @@ jobs:
runs-on: ubuntu-latest
needs: [analyze-and-test]
timeout-minutes: 10
if: ${{ github.event.pull_request.draft == false }}
if: ${{ false }} # ${{ github.event.pull_request.draft == false }}

steps:
- uses: actions/checkout@v2
Expand Down
31 changes: 31 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,38 @@ linter:
- use_test_throws_matchers
- use_to_and_as_if_applicable

dart_code_metrics:
metrics:
cyclomatic-complexity: 20
number-of-arguments: 4
maximum-nesting-level: 5
metrics-exclude:
- test/**
rules:
- always-remove-listener
- avoid-returning-widgets
- avoid-unnecessary-setstate
- avoid-wrapping-in-padding
- binary-expression-operand-order
- double-literal-format
# - member-ordering-extended
- newline-before-return
- no-boolean-literal-compare
- no-equal-then-else
# - no-magic-number
- prefer-conditional-expressions
# - prefer-extracting-callbacks
- prefer-match-file-name:
exclude:
- test/**
- prefer-trailing-comma
- prefer-single-widget-per-file:
ignore-private-widgets: true

analyzer:
plugins:
- dart_code_metrics

errors:
always_put_required_named_parameters_first: ignore
always_use_package_imports: ignore
Expand Down
1 change: 1 addition & 0 deletions lib/utils/iterable_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ extension IterableExtension<E> on Iterable<E> {
} else if (E == String) {
nextValue ??= (current) {
final charCodes = (current as String).codeUnits.map((a) => a + 1);

return String.fromCharCodes(charCodes) as E;
};
} else if (nextValue == null) {
Expand Down
1 change: 1 addition & 0 deletions lib/utils/time_of_day_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extension TimeOfDayExtension on TimeOfDay {
int compareTo(TimeOfDay? other) {
if (other == null) return 1;
if (other == this) return 0;

return inMinutes.compareTo(other.inMinutes);
}
}
6 changes: 3 additions & 3 deletions lib/widgets/booking/booking_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BookingCard extends StatelessWidget {
tileMode: TileMode.repeated,
),
),
child: BookingCardInfo(
child: _BookingCardInfo(
cabin: cabin,
booking: booking,
isRecurring: isRecurring,
Expand All @@ -93,12 +93,12 @@ class BookingCard extends StatelessWidget {
}
}

class BookingCardInfo extends StatelessWidget {
class _BookingCardInfo extends StatelessWidget {
final Cabin cabin;
final Booking booking;
final bool isRecurring;

const BookingCardInfo({
const _BookingCardInfo({
Key? key,
required this.cabin,
required this.booking,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/booking/booking_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:cabin_booking/model/cabin_manager.dart';
import 'package:cabin_booking/model/recurring_booking.dart';
import 'package:cabin_booking/utils/date_time_extension.dart';
import 'package:cabin_booking/utils/time_of_day_extension.dart';
import 'package:cabin_booking/widgets/booking/periodicity_dropdown.dart';
import 'package:cabin_booking/widgets/booking/periodicity_list_tile.dart';
import 'package:cabin_booking/widgets/cabin/cabin_dropdown.dart';
import 'package:cabin_booking/widgets/layout/date_form_field.dart';
import 'package:cabin_booking/widgets/layout/item_info.dart';
Expand Down
7 changes: 4 additions & 3 deletions lib/widgets/booking/bookings_stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class BookingsStack extends StatelessWidget {
}) : super(key: key);

Key _emptyBookingSlotKey(DateTime dateTime, int index) => Key(
'${dateTime.toIso8601String().split('T').first}-'
'$key-'
'$index',
'${dateTime.toIso8601String().split('T').first}'
'-$key'
'-$index',
);

List<Widget> _distributedBookings(BuildContext context) {
Expand Down Expand Up @@ -109,6 +109,7 @@ class BookingsStack extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
// ignore: avoid-returning-widgets
children: _distributedBookings(context),
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/widgets/booking/empty_booking_slot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class EmptyBookingSlot extends StatelessWidget {
child: duration.compareTo(kMinSlotDuration) < 0 ||
endDateTime.compareTo(now) < 0
? null
: EmptyBookingSlotActionable(
: _EmptyBookingSlotActionable(
cabin: cabin,
startDateTime: startsBeforeNow ? now : startDateTime,
endDateTime: endDateTime,
Expand All @@ -77,13 +77,13 @@ class EmptyBookingSlot extends StatelessWidget {
}
}

class EmptyBookingSlotActionable extends StatelessWidget {
class _EmptyBookingSlotActionable extends StatelessWidget {
final Cabin cabin;
final DateTime startDateTime;
final DateTime endDateTime;
final int? preciseDuration;

const EmptyBookingSlotActionable({
const _EmptyBookingSlotActionable({
Key? key,
required this.cabin,
required this.startDateTime,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/item/activity_line_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ActivityLineChart extends StatelessWidget {

@override
Widget build(BuildContext context) {
return ConditionalParentWidget(
return ConditionalWidgetWrap(
condition: tooltipMessage != null,
conditionalBuilder: (child) {
return Tooltip(
Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/layout/conditional_widget_wrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import 'package:flutter/widgets.dart';
///
/// return shouldIncludeParent ? SomeParentWidget(child: child) : child;
/// ```
class ConditionalParentWidget extends StatelessWidget {
class ConditionalWidgetWrap extends StatelessWidget {
/// The subtree that should always be build.
final Widget child;

Expand All @@ -43,7 +43,7 @@ class ConditionalParentWidget extends StatelessWidget {
/// Builds the parent with the subtree [child].
final Widget Function(Widget) conditionalBuilder;

const ConditionalParentWidget({
const ConditionalWidgetWrap({
required this.child,
required this.condition,
required this.conditionalBuilder,
Expand All @@ -53,6 +53,7 @@ class ConditionalParentWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (condition) return conditionalBuilder(child);

return child;
}
}
2 changes: 1 addition & 1 deletion lib/widgets/layout/detailed_figure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DetailedFigure<T> extends StatelessWidget {

final filteredDetails = details.filterFalsy;

return ConditionalParentWidget(
return ConditionalWidgetWrap(
condition: filteredDetails.length > 1 && tooltipMessage != null,
conditionalBuilder: (child) {
return Tooltip(
Expand Down
30 changes: 30 additions & 0 deletions lib/widgets/layout/statistic_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';

class StatisticItem extends StatelessWidget {
final String? label;
final Widget item;

const StatisticItem({
Key? key,
this.label,
required this.item,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (label != null)
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
label!,
style: Theme.of(context).textTheme.subtitle2,
),
),
item,
],
);
}
}
24 changes: 24 additions & 0 deletions lib/widgets/layout/statistic_simple_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:cabin_booking/widgets/layout/statistic_item.dart';
import 'package:flutter/material.dart';

class StatisticSimpleItem<T> extends StatelessWidget {
final String? label;
final T value;

const StatisticSimpleItem({
Key? key,
this.label,
required this.value,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return StatisticItem(
label: label,
item: Text(
'$value',
style: Theme.of(context).textTheme.headline5,
),
);
}
}
93 changes: 27 additions & 66 deletions lib/widgets/layout/statistics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class Statistics extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);

return Card(
child: InkWell(
onTap: onTap,
Expand All @@ -28,29 +26,7 @@ class Statistics extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (icon != null || title != null)
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Row(
mainAxisSize: MainAxisSize.min,
textBaseline: TextBaseline.ideographic,
children: [
if (icon != null)
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Icon(
icon,
size: 18.0,
color: theme.hintColor,
),
),
if (title != null)
Text(
title!,
style: theme.textTheme.subtitle1,
),
],
),
),
_StatisticsHeading(title: title, icon: icon),
Wrap(
spacing: 24.0,
runSpacing: 24.0,
Expand All @@ -64,52 +40,37 @@ class Statistics extends StatelessWidget {
}
}

class StatisticItem extends StatelessWidget {
final String? label;
final Widget item;
class _StatisticsHeading extends StatelessWidget {
final String? title;
final IconData? icon;

const StatisticItem({
Key? key,
this.label,
required this.item,
}) : super(key: key);
const _StatisticsHeading({Key? key, this.title, this.icon}) : super(key: key);

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (label != null)
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
label!,
style: Theme.of(context).textTheme.subtitle2,
),
),
item,
],
);
}
}

class StatisticSimpleItem<T> extends StatelessWidget {
final String? label;
final T value;

const StatisticSimpleItem({
Key? key,
this.label,
required this.value,
}) : super(key: key);
final theme = Theme.of(context);

@override
Widget build(BuildContext context) {
return StatisticItem(
label: label,
item: Text(
'$value',
style: Theme.of(context).textTheme.headline5,
return Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Row(
mainAxisSize: MainAxisSize.min,
textBaseline: TextBaseline.ideographic,
children: [
if (icon != null)
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Icon(
icon,
size: 18.0,
color: theme.hintColor,
),
),
if (title != null)
Text(
title!,
style: theme.textTheme.subtitle1,
),
],
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/layout/striped_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StripedBackground extends StatelessWidget {
Key? key,
required this.startTime,
required this.endTime,
this.height = 60.0 * kBookingHeightRatio,
this.height = kBookingHeightRatio * 60.0,
}) : super(key: key);

int get rowCount => (endTime.hour - startTime.hour).abs() + 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/layout/time_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TimeColumn extends StatelessWidget {
for (var hour = start.hour; hour <= end.hour; hour++)
Container(
width: kTimeColumnWidth,
height: 60.0 * kBookingHeightRatio,
height: kBookingHeightRatio * 60.0,
padding: const EdgeInsets.all(16.0),
alignment: Alignment.topCenter,
child: Text(
Expand Down
Loading

0 comments on commit 0dff4d6

Please sign in to comment.