diff --git a/CHANGELOG.md b/CHANGELOG.md index eab9de81..12e7101d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [2.2.0+3] +* Address DCM lints: + * Prefer `const BorderRadius.all` + * Sort private members + ## [2.2.0+2] * Formatter updates diff --git a/example/pubspec.lock b/example/pubspec.lock index 7729c142..f2be72f1 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -182,7 +182,7 @@ packages: path: ".." relative: true source: path - version: "2.2.0+2" + version: "2.2.0+3" macos_window_utils: dependency: transitive description: diff --git a/lib/src/buttons/checkbox.dart b/lib/src/buttons/checkbox.dart index 9c966447..9695a500 100644 --- a/lib/src/buttons/checkbox.dart +++ b/lib/src/buttons/checkbox.dart @@ -193,6 +193,24 @@ class _CheckboxStack extends StatelessWidget { final bool isMainWindow; final double size; + Color _getCheckmarkColor() { + if (isDisabled) { + return const MacosColor.fromRGBO(172, 172, 172, 1.0); + } + + if (theme.brightness.isDark) { + return theme.accentColor == AccentColor.graphite && isMainWindow + ? MacosColors.black + : MacosColors.white; + } + + if (theme.isMainWindow == false) { + return MacosColors.black; + } + + return MacosColors.white; + } + @override Widget build(BuildContext context) { final icon = value == false @@ -214,24 +232,6 @@ class _CheckboxStack extends StatelessWidget { ], ); } - - Color _getCheckmarkColor() { - if (isDisabled) { - return const MacosColor.fromRGBO(172, 172, 172, 1.0); - } - - if (theme.brightness.isDark) { - return theme.accentColor == AccentColor.graphite && isMainWindow - ? MacosColors.black - : MacosColors.white; - } - - if (theme.isMainWindow == false) { - return MacosColors.black; - } - - return MacosColors.white; - } } /// A widget that paints an inner drop shadow for the checkbox in light mode. diff --git a/lib/src/buttons/popup_button.dart b/lib/src/buttons/popup_button.dart index d6d717b0..e862d9c5 100644 --- a/lib/src/buttons/popup_button.dart +++ b/lib/src/buttons/popup_button.dart @@ -1407,7 +1407,9 @@ class _UpDownCaretsPainter extends CustomPainter { /// Draw background canvas.drawRRect( - BorderRadius.circular(radius).toRRect(Offset.zero & size), + const BorderRadius.all( + Radius.circular(radius), + ).toRRect(Offset.zero & size), Paint()..color = backgroundColor, ); diff --git a/lib/src/buttons/pulldown_button.dart b/lib/src/buttons/pulldown_button.dart index 9f63c5c7..74e7b20b 100644 --- a/lib/src/buttons/pulldown_button.dart +++ b/lib/src/buttons/pulldown_button.dart @@ -1093,7 +1093,9 @@ class _DownCaretPainter extends CustomPainter { /// Draw background canvas.drawRRect( - BorderRadius.circular(radius).toRRect(Offset.zero & size), + const BorderRadius.all( + Radius.circular(radius), + ).toRRect(Offset.zero & size), Paint()..color = backgroundColor, ); diff --git a/lib/src/fields/text_field.dart b/lib/src/fields/text_field.dart index d2ac2f60..c62f2039 100644 --- a/lib/src/fields/text_field.dart +++ b/lib/src/fields/text_field.dart @@ -951,6 +951,7 @@ class _MacosTextFieldState extends State @override bool get selectionEnabled => widget.selectionEnabled; + // End of API for TextSelectionGestureDetectorBuilderDelegate. @override @@ -1185,49 +1186,6 @@ class _MacosTextFieldState extends State ); } - @override - void restoreState(RestorationBucket? oldBucket, bool initialRestore) { - if (_controller != null) { - _registerController(); - } - } - - @override - String? get restorationId => widget.restorationId; - - @override - void dispose() { - _focusNode?.dispose(); - _controller?.dispose(); - _effectiveFocusNode.removeListener(_handleFocusChanged); - super.dispose(); - } - - EditableTextState get _editableText => editableTextKey.currentState!; - - @override - bool get wantKeepAlive => _controller?.value.text.isNotEmpty == true; - - // True if any surrounding decoration widgets will be shown. - bool get _hasDecoration { - return widget.placeholder != null || - widget.clearButtonMode != OverlayVisibilityMode.never || - widget.prefix != null || - widget.suffix != null; - } - - // Provide default behavior if widget.textAlignVertical is not set. - // TextField has top alignment by default, unless it has decoration - // like a prefix or suffix, in which case it's aligned to the center. - TextAlignVertical get _textAlignVertical { - if (widget.textAlignVertical != null) { - return widget.textAlignVertical!; - } - return widget.maxLines == null || widget.maxLines! > 1 - ? TextAlignVertical.center - : TextAlignVertical.top; - } - Color? _resolveAccentColor(BuildContext context, AccentColor? accentColor) { if (accentColor == null) { return null; @@ -1276,6 +1234,49 @@ class _MacosTextFieldState extends State } } + @override + void restoreState(RestorationBucket? oldBucket, bool initialRestore) { + if (_controller != null) { + _registerController(); + } + } + + @override + String? get restorationId => widget.restorationId; + + @override + void dispose() { + _focusNode?.dispose(); + _controller?.dispose(); + _effectiveFocusNode.removeListener(_handleFocusChanged); + super.dispose(); + } + + EditableTextState get _editableText => editableTextKey.currentState!; + + @override + bool get wantKeepAlive => _controller?.value.text.isNotEmpty == true; + + // True if any surrounding decoration widgets will be shown. + bool get _hasDecoration { + return widget.placeholder != null || + widget.clearButtonMode != OverlayVisibilityMode.never || + widget.prefix != null || + widget.suffix != null; + } + + // Provide default behavior if widget.textAlignVertical is not set. + // TextField has top alignment by default, unless it has decoration + // like a prefix or suffix, in which case it's aligned to the center. + TextAlignVertical get _textAlignVertical { + if (widget.textAlignVertical != null) { + return widget.textAlignVertical!; + } + return widget.maxLines == null || widget.maxLines! > 1 + ? TextAlignVertical.center + : TextAlignVertical.top; + } + @override // ignore: code-metrics Widget build(BuildContext context) { diff --git a/lib/src/indicators/capacity_indicators.dart b/lib/src/indicators/capacity_indicators.dart index 826d26d5..57d6ab59 100644 --- a/lib/src/indicators/capacity_indicators.dart +++ b/lib/src/indicators/capacity_indicators.dart @@ -225,7 +225,9 @@ class _CapacityCellPainter extends CustomPainter { /// Draw background canvas.drawRRect( - BorderRadius.circular(radius).toRRect(Offset.zero & size), + const BorderRadius.all( + Radius.circular(radius), + ).toRRect(Offset.zero & size), Paint()..color = backgroundColor, ); @@ -242,7 +244,9 @@ class _CapacityCellPainter extends CustomPainter { /// Draw border canvas.drawRRect( - BorderRadius.circular(radius).toRRect(Offset.zero & size), + const BorderRadius.all( + Radius.circular(radius), + ).toRRect(Offset.zero & size), Paint() ..color = borderColor ..style = PaintingStyle.stroke diff --git a/lib/src/layout/sidebar/sidebar_items.dart b/lib/src/layout/sidebar/sidebar_items.dart index 5008311e..43e8b82e 100644 --- a/lib/src/layout/sidebar/sidebar_items.dart +++ b/lib/src/layout/sidebar/sidebar_items.dart @@ -228,6 +228,25 @@ class _SidebarHeaderItem extends StatelessWidget { bool get hasLeading => item.leading != null; bool get hasTrailing => item.trailing != null; + DefaultTextStyle _buildLabelWithDefaultTextStyle( + TextStyle labelStyle, + BuildContext context, + ) { + final isDarkModeEnabled = MacosTheme.of(context).brightness.isDark; + + return DefaultTextStyle( + style: labelStyle.copyWith( + fontWeight: FontWeight.bold, + fontSize: (labelStyle.fontSize ?? 14.0) * 0.85, + color: isDarkModeEnabled + ? MacosColors.white.withValues(alpha: 0.3) + : MacosColors.black.withValues(alpha: 0.3), + overflow: TextOverflow.ellipsis, + ), + child: item.label, + ); + } + @override Widget build(BuildContext context) { assert(debugCheckHasMacosTheme(context)); @@ -235,6 +254,7 @@ class _SidebarHeaderItem extends StatelessWidget { final double spacing = 10.0 + theme.visualDensity.horizontal; final itemSize = _SidebarItemsConfiguration.of(context).itemSize; + TextStyle? labelStyle; switch (itemSize) { case SidebarItemSize.small: @@ -289,25 +309,6 @@ class _SidebarHeaderItem extends StatelessWidget { ), ); } - - DefaultTextStyle _buildLabelWithDefaultTextStyle( - TextStyle labelStyle, - BuildContext context, - ) { - final isDarkModeEnabled = MacosTheme.of(context).brightness.isDark; - - return DefaultTextStyle( - style: labelStyle.copyWith( - fontWeight: FontWeight.bold, - fontSize: (labelStyle.fontSize ?? 14.0) * 0.85, - color: isDarkModeEnabled - ? MacosColors.white.withValues(alpha: 0.3) - : MacosColors.black.withValues(alpha: 0.3), - overflow: TextOverflow.ellipsis, - ), - child: item.label, - ); - } } /// A macOS style navigation-list item intended for use in a [Sidebar] @@ -336,6 +337,36 @@ class _SidebarItem extends StatelessWidget { void _handleActionTap() => onClick?.call(); + DefaultTextStyle _buildLabelWithDefaultTextStyle( + TextStyle labelStyle, + Color selectedColor, + BuildContext context, + ) { + if (item.section ?? true) { + final isDarkModeEnabled = MacosTheme.of(context).brightness.isDark; + + return DefaultTextStyle( + style: labelStyle.copyWith( + fontWeight: FontWeight.bold, + fontSize: (labelStyle.fontSize ?? 14.0) * 0.85, + color: isDarkModeEnabled + ? MacosColors.white.withValues(alpha: 0.3) + : MacosColors.black.withValues(alpha: 0.3), + overflow: TextOverflow.ellipsis, + ), + child: item.label, + ); + } + + return DefaultTextStyle( + style: labelStyle.copyWith( + color: selected ? textLuminance(selectedColor) : null, + overflow: TextOverflow.ellipsis, + ), + child: item.label, + ); + } + Map> get _actionMap => >{ ActivateIntent: CallbackAction( onInvoke: (ActivateIntent intent) => _handleActionTap(), @@ -344,8 +375,8 @@ class _SidebarItem extends StatelessWidget { onInvoke: (ButtonActivateIntent intent) => _handleActionTap(), ), }; - bool get hasLeading => item.leading != null; + bool get hasTrailing => item.trailing != null; @override @@ -366,6 +397,7 @@ class _SidebarItem extends StatelessWidget { final double spacing = 10.0 + theme.visualDensity.horizontal; final itemSize = _SidebarItemsConfiguration.of(context).itemSize; + TextStyle? labelStyle; switch (itemSize) { case SidebarItemSize.small: @@ -442,36 +474,6 @@ class _SidebarItem extends StatelessWidget { ), ); } - - DefaultTextStyle _buildLabelWithDefaultTextStyle( - TextStyle labelStyle, - Color selectedColor, - BuildContext context, - ) { - if (item.section ?? true) { - final isDarkModeEnabled = MacosTheme.of(context).brightness.isDark; - - return DefaultTextStyle( - style: labelStyle.copyWith( - fontWeight: FontWeight.bold, - fontSize: (labelStyle.fontSize ?? 14.0) * 0.85, - color: isDarkModeEnabled - ? MacosColors.white.withValues(alpha: 0.3) - : MacosColors.black.withValues(alpha: 0.3), - overflow: TextOverflow.ellipsis, - ), - child: item.label, - ); - } - - return DefaultTextStyle( - style: labelStyle.copyWith( - color: selected ? textLuminance(selectedColor) : null, - overflow: TextOverflow.ellipsis, - ), - child: item.label, - ); - } } class _DisclosureSidebarHeaderItem extends StatefulWidget { diff --git a/pubspec.yaml b/pubspec.yaml index dafdcde6..e71b9ba5 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: 2.2.0+2 +version: 2.2.0+3 homepage: "https://macosui.dev" repository: "https://github.com/GroovinChip/macos_ui" diff --git a/test/buttons/pulldown_button_test.dart b/test/buttons/pulldown_button_test.dart index b6e571ca..0e5b7a88 100644 --- a/test/buttons/pulldown_button_test.dart +++ b/test/buttons/pulldown_button_test.dart @@ -1,3 +1,5 @@ +// ignore_for_file: prefer-trailing-comma + import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/test/indicators/capacity_indicators_test.dart b/test/indicators/capacity_indicators_test.dart index 9373ce74..74c50cfc 100644 --- a/test/indicators/capacity_indicators_test.dart +++ b/test/indicators/capacity_indicators_test.dart @@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:macos_ui/macos_ui.dart'; -// TODO(): Remove once mock_canvas in flutter_test reaches stable. +// TODO: Remove once mock_canvas in flutter_test reaches stable. import '../mock_canvas.dart'; void main() {