diff --git a/CHANGELOG.md b/CHANGELOG.md index 97e63f9e..343ebb3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ +## [1.9.1] +* Adds optional `initialDate` to `MacosDatePicker` + ## [1.9.0] * Implement `MacosSlider` ## [1.8.0] 🚨 Breaking Changes 🚨 -* `ContentArea.builder` has been changed from a `ScrollableWidgetBuilder` to a `WidgetBuilder` due to +* `ContentArea.builder` has been changed from a `ScrollableWidgetBuilder` to a `WidgetBuilder` due to changes in Flutter 3.7. The `MacosScrollBar` widget needs to undergo radical changes in order to achieve the native macOS scrollbar look and feel in the future, so this will be revisited at that time. @@ -34,20 +37,20 @@ Other changes ## [1.7.0] * ✨ New - * `MacosImageIcon` widget. Identical to the `ImageIcon` from `flutter/widgets.dart` except it will obey a + * `MacosImageIcon` widget. Identical to the `ImageIcon` from `flutter/widgets.dart` except it will obey a `MacosIconThemeData` instead of an `IconThemeData` * `SidebarItemSize` enum, which determines the height of sidebar items and the maximum size their `leading` widgets. * `SidebarItem` now accepts an optional `trailing` widget. * 🔄 Updated - * `SidebarItems` now supports `SidebarItemSize` via the `itemSize` property, which defaults to -`SidebarItemSize.medium`. The widget has been updated to manage the item's height, the maximum size of the item's + * `SidebarItems` now supports `SidebarItemSize` via the `itemSize` property, which defaults to +`SidebarItemSize.medium`. The widget has been updated to manage the item's height, the maximum size of the item's leading widget, and the font size of the item's label widget according to the given `SidebarItemSize`. * The example app has been tweaked to use some icons from the SF Symbols 4 Beta via the new `MacosImageIcon` widget. ## [1.6.0] * New widgets: `MacosTabView` and `MacosTabView` * BREAKING CHANGE: `Label.yAxis` has been renamed to `Label.crossAxisAlignment` -* BREAKING CHANGE: `TooltipTheme` and `TooltipThemeData` have been renamed to `MacosTooltipTheme` and +* BREAKING CHANGE: `TooltipTheme` and `TooltipThemeData` have been renamed to `MacosTooltipTheme` and `MacosTooltipThemeData` ## [1.5.1] @@ -64,14 +67,14 @@ leading widget, and the font size of the item's label widget according to the gi * Update `pubspec.yaml` with `repository` and new `homepage` field. ## [1.4.1] -* Fixes an issue where if the app was displayed in full screen mode, an opaque empty toolbar would appear at the top [#249](https://github.com/GroovinChip/macos_ui/issues/249) - +* Fixes an issue where if the app was displayed in full screen mode, an opaque empty toolbar would appear at the top [#249](https://github.com/GroovinChip/macos_ui/issues/249) + ## [1.4.0] * Migration to Flutter 3.0 * Minimum dart sdk version is now 2.17.0 * Use new super parameters feature * Update to `flutter_lints: ^2.0.1` with subsequent fixes - * `MacosScrollbar` API more closely matches its material counterpart + * `MacosScrollbar` API more closely matches its material counterpart * Update `MacosColor` to more closely match the `Color` class * Adds `MacosColor.fromARGB` constructor * Adds `MacosColor.fromRGBO` constructor @@ -86,7 +89,7 @@ leading widget, and the font size of the item's label widget according to the gi * Fix `MacosApp` documentation ## [1.2.1] -* Fixes issue with error thrown when toolbar actions are modified programmatically [#239](https://github.com/GroovinChip/macos_ui/issues/239) +* Fixes issue with error thrown when toolbar actions are modified programmatically [#239](https://github.com/GroovinChip/macos_ui/issues/239) ## [1.2.0] * Improved styling for `MacosTooltip`: @@ -144,7 +147,7 @@ leading widget, and the font size of the item's label widget according to the gi * Switch over to `flutter_lints` ## [0.12.4+1] -* Improve visual design of `MacosPopupButton` and `MacosPulldownButton`, to better match the styling and translucency effect of Apple design. +* Improve visual design of `MacosPopupButton` and `MacosPulldownButton`, to better match the styling and translucency effect of Apple design. * Remove unnecessary properties of `MacosPopupButton` ## [0.12.4] @@ -194,7 +197,7 @@ leading widget, and the font size of the item's label widget according to the gi ## [0.10.0] * New widget - `MacosIcon`! `MacosIcon` is identical to regular icons, with the exception that it respects a `MacosTheme`. Also includes corresponding theme classes -* `MacosThemeData` now sets a global, configurable `iconTheme` for `MacosIcon`s +* `MacosThemeData` now sets a global, configurable `iconTheme` for `MacosIcon`s ## [0.9.3] * Update to `PushButton`: @@ -257,7 +260,7 @@ leading widget, and the font size of the item's label widget according to the gi ## [0.6.0] * Improved `MacosAlertDialog` design * Added `showMacosAlertDialog` to display a `MacosAlertDialog` with standard macOS animations and behaviour. - + ## [0.5.2] * Fixes maximum height issue with `MacosAlertDialog` @@ -372,11 +375,11 @@ leading widget, and the font size of the item's label widget according to the gi ## [0.0.4] * Major theme refactor that more closely resembles flutter/material and flutter/cupertino * The `Style` class is now `MacosThemeData` - * `MacosTheme` is now a `StatelessWidget` that returns a private `_InheritedMacosTheme`. + * `MacosTheme` is now a `StatelessWidget` that returns a private `_InheritedMacosTheme`. The static `MacosTheme.of(context)` is now defined here. - * `MacosApp` now takes a `theme` and `darkTheme` rather than `style` and `darkStyle`. - Additionally, there are minor changes to the way `MacosApp` is built that more closely - resemble how `MaterialApp` is built. + * `MacosApp` now takes a `theme` and `darkTheme` rather than `style` and `darkStyle`. + Additionally, there are minor changes to the way `MacosApp` is built that more closely + resemble how `MaterialApp` is built. ## [0.0.3] diff --git a/README.md b/README.md index f88241c4..a697ca0c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Guides, codelabs, and other documentation can be found at https://macosui.dev -## 🚨 Usage notes +## 🚨 Usage notes ### Platform Compatibility pub.dev shows that `macos_ui` only supports macOS. This is because `macos_ui` calls some native code, and therefore diff --git a/example/pubspec.lock b/example/pubspec.lock index 47da932b..b0517c99 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -97,7 +97,7 @@ packages: path: ".." relative: true source: path - version: "1.9.0" + version: "1.9.1" matcher: dependency: transitive description: diff --git a/lib/src/selectors/date_picker.dart b/lib/src/selectors/date_picker.dart index 32c1501d..d11d3d4b 100644 --- a/lib/src/selectors/date_picker.dart +++ b/lib/src/selectors/date_picker.dart @@ -43,6 +43,7 @@ class MacosDatePicker extends StatefulWidget { super.key, this.style = DatePickerStyle.combined, required this.onDateChanged, + this.initialDate, }); /// The [DatePickerStyle] to use. @@ -53,12 +54,19 @@ class MacosDatePicker extends StatefulWidget { /// {macro onDateChanged} final OnDateChanged onDateChanged; + /// Set an initial date for the picker. + /// + /// Defaults to `DateTime.now()`. + final DateTime? initialDate; + @override State createState() => _MacosDatePickerState(); } class _MacosDatePickerState extends State { - final _initialDate = DateTime.now(); + final _today = DateTime.now(); + late final _initialDate = widget.initialDate ?? _today; + late int _selectedDay; late int _selectedMonth; late int _selectedYear; @@ -474,7 +482,7 @@ class _MacosDatePickerState extends State { DateTime(_selectedYear, _selectedMonth, _selectedDay), dayToBuild, ); - final isToday = DateUtils.isSameDay(_initialDate, dayToBuild); + final isToday = DateUtils.isSameDay(_today, dayToBuild); BoxDecoration? decoration; Widget? dayText; diff --git a/pubspec.yaml b/pubspec.yaml index db2162f8..4ffe3e99 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: macos_ui description: Flutter widgets and themes implementing the current macOS design language. -version: 1.9.0 +version: 1.9.1 homepage: "https://macosui.dev" repository: "https://github.com/GroovinChip/macos_ui" diff --git a/test/selectors/date_picker_test.dart b/test/selectors/date_picker_test.dart index 5823869e..80e00bf8 100644 --- a/test/selectors/date_picker_test.dart +++ b/test/selectors/date_picker_test.dart @@ -6,7 +6,45 @@ import 'package:macos_ui/macos_ui.dart'; void main() { group('MacosDatePicker tests', () { testWidgets( - 'Textual MacosDatePicker renders the expected date', + 'Textual MacosDatePicker renders the expected initial date', + (tester) async { + final initialDate = DateTime.now().add(const Duration(days: 30)); + await tester.pumpWidget( + MacosApp( + home: MacosWindow( + child: MacosScaffold( + children: [ + ContentArea( + builder: (context) { + return Center( + child: MacosDatePicker( + onDateChanged: (date) {}, + initialDate: initialDate, + style: DatePickerStyle.textual, + ), + ); + }, + ), + ], + ), + ), + ), + ); + + expect(find.text('/'), findsNWidgets(2)); + expect(find.text('${initialDate.year}'), findsOneWidget); + if (initialDate.month == initialDate.day) { + expect(find.text('${initialDate.day}'), findsNWidgets(2)); + expect(find.text('${initialDate.month}'), findsNWidgets(2)); + } else { + expect(find.text('${initialDate.day}'), findsOneWidget); + expect(find.text('${initialDate.month}'), findsOneWidget); + } + }, + ); + + testWidgets( + "Textual MacosDatePicker renders the today's date by default", (tester) async { final today = DateTime.now(); await tester.pumpWidget(