Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [2.2.0+3]
* Address DCM lints:
* Prefer `const BorderRadius.all`
* Sort private members

## [2.2.0+2]
* Formatter updates

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 18 additions & 18 deletions lib/src/buttons/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion lib/src/buttons/popup_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
4 changes: 3 additions & 1 deletion lib/src/buttons/pulldown_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
87 changes: 44 additions & 43 deletions lib/src/fields/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ class _MacosTextFieldState extends State<MacosTextField>

@override
bool get selectionEnabled => widget.selectionEnabled;

// End of API for TextSelectionGestureDetectorBuilderDelegate.

@override
Expand Down Expand Up @@ -1185,49 +1186,6 @@ class _MacosTextFieldState extends State<MacosTextField>
);
}

@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;
Expand Down Expand Up @@ -1276,6 +1234,49 @@ class _MacosTextFieldState extends State<MacosTextField>
}
}

@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) {
Expand Down
8 changes: 6 additions & 2 deletions lib/src/indicators/capacity_indicators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand All @@ -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
Expand Down
102 changes: 52 additions & 50 deletions lib/src/layout/sidebar/sidebar_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,33 @@ 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));
final theme = MacosTheme.of(context);

final double spacing = 10.0 + theme.visualDensity.horizontal;
final itemSize = _SidebarItemsConfiguration.of(context).itemSize;

TextStyle? labelStyle;
switch (itemSize) {
case SidebarItemSize.small:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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<Type, Action<Intent>> get _actionMap => <Type, Action<Intent>>{
ActivateIntent: CallbackAction<ActivateIntent>(
onInvoke: (ActivateIntent intent) => _handleActionTap(),
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 2 additions & 0 deletions test/buttons/pulldown_button_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/indicators/capacity_indicators_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading