diff --git a/forui/example/lib/main.dart b/forui/example/lib/main.dart index d22d19137..6755d86ea 100644 --- a/forui/example/lib/main.dart +++ b/forui/example/lib/main.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:forui/forui.dart'; import 'package:forui_example/example.dart'; - void main() { runApp(const Application()); } diff --git a/forui/lib/src/foundation/inkwell.dart b/forui/lib/src/foundation/inkwell.dart index 31f45e7fe..4ee4cd0cc 100644 --- a/forui/lib/src/foundation/inkwell.dart +++ b/forui/lib/src/foundation/inkwell.dart @@ -1,5 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; + import 'package:meta/meta.dart'; @internal diff --git a/forui/lib/src/widgets/calendar/calendar.dart b/forui/lib/src/widgets/calendar/calendar.dart index e2a03f38f..e2e2018aa 100644 --- a/forui/lib/src/widgets/calendar/calendar.dart +++ b/forui/lib/src/widgets/calendar/calendar.dart @@ -1,12 +1,14 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; + +import 'package:sugar/sugar.dart'; + import 'package:forui/forui.dart'; import 'package:forui/src/widgets/calendar/day/day_picker.dart'; import 'package:forui/src/widgets/calendar/day/paged_day_picker.dart'; import 'package:forui/src/widgets/calendar/shared/header.dart'; import 'package:forui/src/widgets/calendar/year_month_picker.dart'; -import 'package:sugar/sugar.dart'; export 'day/day_picker.dart' show FCalendarDayPickerStyle, FCalendarDayStyle; export 'shared/entry.dart' show FCalendarEntryStyle; diff --git a/forui/lib/src/widgets/calendar/calendar_controller.dart b/forui/lib/src/widgets/calendar/calendar_controller.dart index 35e3dc762..ea2d8b710 100644 --- a/forui/lib/src/widgets/calendar/calendar_controller.dart +++ b/forui/lib/src/widgets/calendar/calendar_controller.dart @@ -1,7 +1,9 @@ import 'package:flutter/widgets.dart'; -import 'package:forui/forui.dart'; + import 'package:sugar/sugar.dart'; +import 'package:forui/forui.dart'; + /// A controller that controls date selection in a calendar. /// /// This class should be extended to customize date selection. By default, the following controllers are provided: diff --git a/forui/lib/src/widgets/calendar/day/day_picker.dart b/forui/lib/src/widgets/calendar/day/day_picker.dart index 268734b0b..c92e06491 100644 --- a/forui/lib/src/widgets/calendar/day/day_picker.dart +++ b/forui/lib/src/widgets/calendar/day/day_picker.dart @@ -3,16 +3,18 @@ import 'dart:collection'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; -import 'package:forui/forui.dart'; -import 'package:forui/src/widgets/calendar/shared/entry.dart'; + import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/forui.dart'; +import 'package:forui/src/widgets/calendar/shared/entry.dart'; + @internal class DayPicker extends StatefulWidget { static const maxRows = 7; static const tileDimension = 42.0; - + final FCalendarDayPickerStyle style; final LocalDate month; final LocalDate today; @@ -91,35 +93,34 @@ class _DayPickerState extends State { return (first, last); } - @override Widget build(BuildContext context) => SizedBox( - width: DateTime.daysPerWeek * DayPicker.tileDimension, - child: GridView.custom( - padding: EdgeInsets.zero, - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - gridDelegate: const _GridDelegate(), - childrenDelegate: SliverChildListDelegate( - addRepaintBoundaries: false, - [ - ..._headers(context), - for (final MapEntry(key: date, value: focusNode) in _days.entries) - Entry.day( - style: widget.style, - date: date, - focusNode: focusNode, - current: date.month == widget.month.month, - today: date == widget.today, - enabled: widget.enabled, - selected: widget.selected, - onPress: widget.onPress, - onLongPress: widget.onLongPress, - ), - ], - ), - ), - ); + width: DateTime.daysPerWeek * DayPicker.tileDimension, + child: GridView.custom( + padding: EdgeInsets.zero, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + gridDelegate: const _GridDelegate(), + childrenDelegate: SliverChildListDelegate( + addRepaintBoundaries: false, + [ + ..._headers(context), + for (final MapEntry(key: date, value: focusNode) in _days.entries) + Entry.day( + style: widget.style, + date: date, + focusNode: focusNode, + current: date.month == widget.month.month, + today: date == widget.today, + enabled: widget.enabled, + selected: widget.selected, + onPress: widget.onPress, + onLongPress: widget.onLongPress, + ), + ], + ), + ), + ); List _headers(BuildContext context) { final firstDayOfWeek = widget.style.startDayOfWeek ?? DateTime.sunday; // TODO: Localization @@ -158,19 +159,18 @@ class _GridDelegate extends SliverGridDelegate { @override SliverGridLayout getLayout(SliverConstraints constraints) => SliverGridRegularTileLayout( - childCrossAxisExtent: DayPicker.tileDimension, - childMainAxisExtent: DayPicker.tileDimension, - crossAxisCount: DateTime.daysPerWeek, - crossAxisStride: DayPicker.tileDimension, - mainAxisStride: DayPicker.tileDimension, - reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), - ); + childCrossAxisExtent: DayPicker.tileDimension, + childMainAxisExtent: DayPicker.tileDimension, + crossAxisCount: DateTime.daysPerWeek, + crossAxisStride: DayPicker.tileDimension, + mainAxisStride: DayPicker.tileDimension, + reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection), + ); @override bool shouldRelayout(_GridDelegate oldDelegate) => false; } - /// A day picker's style. final class FCalendarDayPickerStyle with Diagnosticable { /// The text style for the day of th week headers. @@ -364,10 +364,10 @@ final class FCalendarDayStyle with Diagnosticable { @override bool operator ==(Object other) => identical(this, other) || - other is FCalendarDayStyle && - runtimeType == other.runtimeType && - unselectedStyle == other.unselectedStyle && - selectedStyle == other.selectedStyle; + other is FCalendarDayStyle && + runtimeType == other.runtimeType && + unselectedStyle == other.unselectedStyle && + selectedStyle == other.selectedStyle; @override int get hashCode => unselectedStyle.hashCode ^ selectedStyle.hashCode; diff --git a/forui/lib/src/widgets/calendar/day/paged_day_picker.dart b/forui/lib/src/widgets/calendar/day/paged_day_picker.dart index 9ec611d66..f98ffe294 100644 --- a/forui/lib/src/widgets/calendar/day/paged_day_picker.dart +++ b/forui/lib/src/widgets/calendar/day/paged_day_picker.dart @@ -1,11 +1,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/semantics.dart'; import 'package:flutter/widgets.dart'; -import 'package:forui/src/widgets/calendar/day/day_picker.dart'; -import 'package:forui/src/widgets/calendar/shared/paged_picker.dart'; + import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/src/widgets/calendar/day/day_picker.dart'; +import 'package:forui/src/widgets/calendar/shared/paged_picker.dart'; + @internal class PagedDayPicker extends PagedPicker { final Predicate selected; diff --git a/forui/lib/src/widgets/calendar/month/month_picker.dart b/forui/lib/src/widgets/calendar/month/month_picker.dart index 6c17bc46b..2d4db053a 100644 --- a/forui/lib/src/widgets/calendar/month/month_picker.dart +++ b/forui/lib/src/widgets/calendar/month/month_picker.dart @@ -1,11 +1,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; -import 'package:forui/src/widgets/calendar/shared/entry.dart'; -import 'package:forui/src/widgets/calendar/year_month_picker.dart'; + import 'package:intl/intl.dart'; import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/src/widgets/calendar/shared/entry.dart'; +import 'package:forui/src/widgets/calendar/year_month_picker.dart'; + // ignore: non_constant_identifier_names final _MMM = DateFormat.MMM(); @@ -30,7 +32,7 @@ class MonthPicker extends StatefulWidget { required this.focused, required this.onPress, super.key, - }): assert(currentYear == currentYear.truncate(to: DateUnit.years), 'currentYear must be truncated to years'); + }) : assert(currentYear == currentYear.truncate(to: DateUnit.years), 'currentYear must be truncated to years'); @override State createState() => _MonthPickerState(); diff --git a/forui/lib/src/widgets/calendar/month/paged_month_picker.dart b/forui/lib/src/widgets/calendar/month/paged_month_picker.dart index 118be0be2..a59e9afc9 100644 --- a/forui/lib/src/widgets/calendar/month/paged_month_picker.dart +++ b/forui/lib/src/widgets/calendar/month/paged_month_picker.dart @@ -1,10 +1,12 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; -import 'package:forui/src/widgets/calendar/month/month_picker.dart'; -import 'package:forui/src/widgets/calendar/shared/paged_picker.dart'; + import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/src/widgets/calendar/month/month_picker.dart'; +import 'package:forui/src/widgets/calendar/shared/paged_picker.dart'; + @internal class PagedMonthPicker extends PagedPicker { final ValueChanged onPress; @@ -32,14 +34,14 @@ class PagedMonthPicker extends PagedPicker { class _PagedMonthPickerState extends PagedPickerState { @override Widget buildItem(BuildContext context, int page) => MonthPicker( - style: widget.style.yearMonthPickerStyle, - currentYear: widget.initial, - start: widget.start, - end: widget.end, - today: widget.today, - focused: focusedDate, - onPress: widget.onPress, - ); + style: widget.style.yearMonthPickerStyle, + currentYear: widget.initial, + start: widget.start, + end: widget.end, + today: widget.today, + focused: focusedDate, + onPress: widget.onPress, + ); @override void onPageChange(int page) {} // Months will only appear on a single page. @@ -74,9 +76,9 @@ class _PagedMonthPickerState extends PagedPickerState { @override Map get directionOffset => const { - TraversalDirection.up: Period(months: -MonthPicker.columns), - TraversalDirection.right: Period(months: 1), - TraversalDirection.down: Period(months: MonthPicker.columns), - TraversalDirection.left: Period(months: -1), - }; + TraversalDirection.up: Period(months: -MonthPicker.columns), + TraversalDirection.right: Period(months: 1), + TraversalDirection.down: Period(months: MonthPicker.columns), + TraversalDirection.left: Period(months: -1), + }; } diff --git a/forui/lib/src/widgets/calendar/shared/entry.dart b/forui/lib/src/widgets/calendar/shared/entry.dart index 708e5248a..7d75c0ad5 100644 --- a/forui/lib/src/widgets/calendar/shared/entry.dart +++ b/forui/lib/src/widgets/calendar/shared/entry.dart @@ -1,12 +1,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; -import 'package:forui/src/foundation/inkwell.dart'; -import 'package:forui/src/widgets/calendar/year_month_picker.dart'; + import 'package:intl/intl.dart'; import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/src/foundation/inkwell.dart'; import 'package:forui/src/widgets/calendar/day/day_picker.dart'; +import 'package:forui/src/widgets/calendar/year_month_picker.dart'; final _yMMMMd = DateFormat.yMMMMd(); @@ -71,7 +72,7 @@ abstract class Entry extends StatelessWidget { required String Function(LocalDate) format, }) { final entryStyle = enabled ? style.enabledStyle : style.disabledStyle; - + // ignore: avoid_positional_boolean_parameters Widget builder(BuildContext context, bool focused, Widget? child) => _Content( style: entryStyle, diff --git a/forui/lib/src/widgets/calendar/shared/header.dart b/forui/lib/src/widgets/calendar/shared/header.dart index 591cc3589..39ddea130 100644 --- a/forui/lib/src/widgets/calendar/shared/header.dart +++ b/forui/lib/src/widgets/calendar/shared/header.dart @@ -1,11 +1,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; -import 'package:forui/forui.dart'; -import 'package:forui/src/foundation/inkwell.dart'; + import 'package:intl/intl.dart'; import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/forui.dart'; +import 'package:forui/src/foundation/inkwell.dart'; + /// The current picker type. enum FCalendarPickerType { /// The day picker. diff --git a/forui/lib/src/widgets/calendar/shared/paged_picker.dart b/forui/lib/src/widgets/calendar/shared/paged_picker.dart index 239ff8b64..b991a9715 100644 --- a/forui/lib/src/widgets/calendar/shared/paged_picker.dart +++ b/forui/lib/src/widgets/calendar/shared/paged_picker.dart @@ -1,11 +1,13 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; -import 'package:forui/src/widgets/calendar/calendar.dart'; -import 'package:forui/src/widgets/calendar/shared/header.dart'; + import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/src/widgets/calendar/calendar.dart'; +import 'package:forui/src/widgets/calendar/shared/header.dart'; + @internal abstract class PagedPicker extends StatefulWidget { final FCalendarStyle style; @@ -23,8 +25,7 @@ abstract class PagedPicker extends StatefulWidget { required this.initial, Predicate? enabled, super.key, - }): - enabled = ((date) => start <= date && date <= end && (enabled?.call(date) ?? true)); + }) : enabled = ((date) => start <= date && date <= end && (enabled?.call(date) ?? true)); @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { diff --git a/forui/lib/src/widgets/calendar/year/paged_year_picker.dart b/forui/lib/src/widgets/calendar/year/paged_year_picker.dart index 34773142e..ceabfe331 100644 --- a/forui/lib/src/widgets/calendar/year/paged_year_picker.dart +++ b/forui/lib/src/widgets/calendar/year/paged_year_picker.dart @@ -1,10 +1,12 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; -import 'package:forui/src/widgets/calendar/shared/paged_picker.dart'; -import 'package:forui/src/widgets/calendar/year/year_picker.dart'; + import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/src/widgets/calendar/shared/paged_picker.dart'; +import 'package:forui/src/widgets/calendar/year/year_picker.dart'; + @internal class PagedYearPicker extends PagedPicker { final ValueChanged onPress; diff --git a/forui/lib/src/widgets/calendar/year/year_picker.dart b/forui/lib/src/widgets/calendar/year/year_picker.dart index c51668b31..492fb9877 100644 --- a/forui/lib/src/widgets/calendar/year/year_picker.dart +++ b/forui/lib/src/widgets/calendar/year/year_picker.dart @@ -1,10 +1,12 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; -import 'package:forui/src/widgets/calendar/shared/entry.dart'; -import 'package:forui/src/widgets/calendar/year_month_picker.dart'; + import 'package:meta/meta.dart'; import 'package:sugar/sugar.dart'; +import 'package:forui/src/widgets/calendar/shared/entry.dart'; +import 'package:forui/src/widgets/calendar/year_month_picker.dart'; + @internal class YearPicker extends StatefulWidget { static const columns = 3; @@ -28,7 +30,7 @@ class YearPicker extends StatefulWidget { required this.focused, required this.onPress, super.key, - }): assert(startYear == startYear.truncate(to: DateUnit.years), 'startYear must be truncated to years.'); + }) : assert(startYear == startYear.truncate(to: DateUnit.years), 'startYear must be truncated to years.'); @override State createState() => _YearPickerState(); diff --git a/forui/lib/src/widgets/calendar/year_month_picker.dart b/forui/lib/src/widgets/calendar/year_month_picker.dart index 9198ea65e..6581eb6da 100644 --- a/forui/lib/src/widgets/calendar/year_month_picker.dart +++ b/forui/lib/src/widgets/calendar/year_month_picker.dart @@ -1,10 +1,12 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; + +import 'package:meta/meta.dart'; +import 'package:sugar/sugar.dart'; + import 'package:forui/forui.dart'; import 'package:forui/src/widgets/calendar/month/paged_month_picker.dart'; import 'package:forui/src/widgets/calendar/year/paged_year_picker.dart'; -import 'package:meta/meta.dart'; -import 'package:sugar/sugar.dart'; @internal class YearMonthPicker extends StatefulWidget { @@ -73,11 +75,11 @@ class _YearMonthPickerState extends State { } } - /// The year/month picker's style. final class FCalendarYearMonthPickerStyle with Diagnosticable { /// The enabled years/months' styles. final FCalendarEntryStyle enabledStyle; + /// The disabled years/months' styles. final FCalendarEntryStyle disabledStyle; @@ -115,10 +117,11 @@ final class FCalendarYearMonthPickerStyle with Diagnosticable { FCalendarYearMonthPickerStyle copyWith({ FCalendarEntryStyle? enabledStyle, FCalendarEntryStyle? disabledStyle, - }) => FCalendarYearMonthPickerStyle( - enabledStyle: enabledStyle ?? this.enabledStyle, - disabledStyle: disabledStyle ?? this.disabledStyle, - ); + }) => + FCalendarYearMonthPickerStyle( + enabledStyle: enabledStyle ?? this.enabledStyle, + disabledStyle: disabledStyle ?? this.disabledStyle, + ); @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { @@ -131,8 +134,10 @@ final class FCalendarYearMonthPickerStyle with Diagnosticable { @override bool operator ==(Object other) => identical(this, other) || - other is FCalendarYearMonthPickerStyle && runtimeType == other.runtimeType && - enabledStyle == other.enabledStyle && disabledStyle == other.disabledStyle; + other is FCalendarYearMonthPickerStyle && + runtimeType == other.runtimeType && + enabledStyle == other.enabledStyle && + disabledStyle == other.disabledStyle; @override int get hashCode => enabledStyle.hashCode ^ disabledStyle.hashCode; diff --git a/forui/test/src/foundation/inkwell_test.dart b/forui/test/src/foundation/inkwell_test.dart index 2dc309a01..654708929 100644 --- a/forui/test/src/foundation/inkwell_test.dart +++ b/forui/test/src/foundation/inkwell_test.dart @@ -1,9 +1,10 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; + import 'package:flutter_test/flutter_test.dart'; + import 'package:forui/forui.dart'; import 'package:forui/src/foundation/inkwell.dart'; - import '../test_scaffold.dart'; void main() { diff --git a/forui/test/src/widgets/calendar/calendar_controller_test.dart b/forui/test/src/widgets/calendar/calendar_controller_test.dart index ed12189d0..820f8bc7a 100644 --- a/forui/test/src/widgets/calendar/calendar_controller_test.dart +++ b/forui/test/src/widgets/calendar/calendar_controller_test.dart @@ -1,4 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; + import 'package:forui/forui.dart'; void main() { diff --git a/forui/test/src/widgets/calendar/calendar_golden_test.dart b/forui/test/src/widgets/calendar/calendar_golden_test.dart index 4fed22c6e..dc78db1f3 100644 --- a/forui/test/src/widgets/calendar/calendar_golden_test.dart +++ b/forui/test/src/widgets/calendar/calendar_golden_test.dart @@ -107,7 +107,6 @@ void main() { await gesture.moveTo(tester.getCenter(find.text('Feb'))); await tester.pumpAndSettle(); - await expectLater( find.byType(TestScaffold), matchesGoldenFile('calendar/month-picker/$name-default.png'), diff --git a/forui/test/src/widgets/calendar/calendar_test.dart b/forui/test/src/widgets/calendar/calendar_test.dart index 53c0c168c..386d31e6c 100644 --- a/forui/test/src/widgets/calendar/calendar_test.dart +++ b/forui/test/src/widgets/calendar/calendar_test.dart @@ -1,6 +1,6 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:forui/forui.dart'; +import 'package:forui/forui.dart'; import '../../test_scaffold.dart'; void main() {