Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DX-2293] Update rules #690

Merged
merged 2 commits into from
Oct 1, 2024
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
6 changes: 4 additions & 2 deletions mews_pedantic/lib/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ dart_code_metrics:
- prefer-correct-error-name
- prefer-correct-for-loop-increment
- prefer-correct-future-return-type
# - prefer-correct-handler-name
- prefer-correct-handler-name
# - prefer-correct-identifier-length
- prefer-correct-json-casts
- prefer-correct-setter-parameter-name
Expand Down Expand Up @@ -568,7 +568,9 @@ dart_code_metrics:
pubspec-rules:
# - avoid-any-version
# - avoid-dependency-overrides
# - banned-dependencies
- banned-dependencies:
banned:
- get
# - prefer-caret-version-syntax
# - prefer-correct-package-name
# - prefer-correct-screenshots
Expand Down
14 changes: 10 additions & 4 deletions optimus/lib/src/lists/nav_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ class _OptimusNavListTileState extends State<OptimusNavListTile>
hovered: tokens.backgroundInteractiveNeutralSubtleHover,
);

void _handleHoverChanged(bool isHovered) {
setState(() => _controller.update(WidgetState.hovered, isHovered));
}

void _handlePressedChanged(bool isPressed) {
setState(() => _controller.update(WidgetState.pressed, isPressed));
}

@override
Widget build(BuildContext context) {
final tokens = context.tokens;
Expand All @@ -101,10 +109,8 @@ class _OptimusNavListTileState extends State<OptimusNavListTile>
return IgnorePointer(
ignoring: !widget.isEnabled,
child: GestureWrapper(
onHoverChanged: (isHovered) =>
setState(() => _controller.update(WidgetState.hovered, isHovered)),
onPressedChanged: (isPressed) =>
setState(() => _controller.update(WidgetState.pressed, isPressed)),
onHoverChanged: _handleHoverChanged,
onPressedChanged: _handlePressedChanged,
child: DecoratedBox(
decoration:
BoxDecoration(color: _backgroundColor.resolve(_controller.value)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class _ProgressIndicatorItemState extends State<ProgressIndicatorItem>
bool _isHovered = false;
bool _isPressed = false;

void _handleHoverChange(bool isHovered) =>
setState(() => _isHovered = isHovered);

void _handlePressChange(bool isPressed) =>
setState(() => _isPressed = isPressed);

@override
Widget build(BuildContext context) {
final indicator = widget.state.isEnabled
Expand All @@ -82,8 +88,8 @@ class _ProgressIndicatorItemState extends State<ProgressIndicatorItem>
final itemsCount = widget.itemsCount;

return GestureWrapper(
onHoverChanged: (isHovered) => setState(() => _isHovered = isHovered),
onPressedChanged: (isPressed) => setState(() => _isPressed = isPressed),
onHoverChanged: _handleHoverChange,
onPressedChanged: _handlePressChange,
child: switch (widget.axis) {
Axis.horizontal => _HorizontalItem(
indicator: indicator,
Expand Down
29 changes: 14 additions & 15 deletions optimus_widgetbook/lib/components/buttons/toggle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,25 @@ class _ToggleExampleState extends State<_ToggleExample> {
bool _isLoading = false;
String _label = 'Claim';

void _handlePressed() {
setState(() => _isLoading = true);
Future.delayed(const Duration(seconds: 2), _handleToggleBack);
}

void _handleToggleBack() {
setState(() {
_isToggled = !_isToggled;
_label = _isToggled ? 'Claimed' : 'Claim';
_isLoading = false;
});
}

@override
Widget build(BuildContext context) => OptimusToggleButton(
label: widget.hasLabel ? Text(_label) : null,
isToggled: _isToggled,
isLoading: _isLoading,
onPressed: widget.isEnabled
? () {
setState(() {
_isLoading = true;
});
Future.delayed(
const Duration(seconds: 2),
() => setState(() {
_isToggled = !_isToggled;
_label = _isToggled ? 'Claimed' : 'Claim';
_isLoading = false;
}),
);
}
: null,
onPressed: widget.isEnabled ? _handlePressed : null,
size: widget.size,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class _DateFieldExampleState extends State<_DateFieldExample> {
_value = DateTime.now();
}

void _handleSubmit(DateTime? value) => setState(() => _value = value);

@override
Widget build(BuildContext context) {
final k = context.knobs;
Expand All @@ -48,7 +50,7 @@ class _DateFieldExampleState extends State<_DateFieldExample> {
isEnabled: isEnabled,
format: DateFormat(format),
isClearAllEnabled: isClearEnabled,
onSubmitted: (value) => setState(() => _value = value),
onSubmitted: _handleSubmit,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class _SelectionCardExample extends StatefulWidget {
class _SelectionCardExampleState extends State<_SelectionCardExample> {
bool _isSelected = false;

void _handlePress() => setState(() => _isSelected = !_isSelected);

@override
Widget build(BuildContext context) {
final k = context.knobs;
Expand Down Expand Up @@ -63,7 +65,7 @@ class _SelectionCardExampleState extends State<_SelectionCardExample> {
selectionVariant: selectorVariant,
borderRadius: borderRadius,
isEnabled: isEnabled,
onPressed: () => setState(() => _isSelected = !_isSelected),
onPressed: _handlePress,
),
);
}
Expand Down
5 changes: 3 additions & 2 deletions optimus_widgetbook/lib/components/list/nav_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class _NavListExample extends StatefulWidget {
class _NavListExampleState extends State<_NavListExample> {
bool _isToggled = false;

void _handleToggle(bool isToggled) => setState(() => _isToggled = isToggled);

@override
Widget build(BuildContext context) {
final k = context.knobs;
Expand Down Expand Up @@ -54,8 +56,7 @@ class _NavListExampleState extends State<_NavListExample> {
rightDetail: rightDetail != null ? Icon(rightDetail) : null,
isChevronVisible: isChevronVisible,
isToggleVisible: isToggleVisible,
onTogglePressed: (isToggled) =>
setState(() => _isToggled = isToggled),
onTogglePressed: _handleToggle,
isToggled: _isToggled,
isEnabled: isEnabled,
leading: leading != null ? Icon(leading) : null,
Expand Down
Loading