Skip to content

Commit

Permalink
Merge pull request #690 from MewsSystems/DX-2293
Browse files Browse the repository at this point in the history
feat: [DX-2293] Update rules
  • Loading branch information
witwash authored Oct 1, 2024
2 parents 20b19ff + 3c02870 commit ba0c400
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
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
10 changes: 8 additions & 2 deletions optimus/lib/src/progress_indicator/progress_indicator_item.dart
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
4 changes: 3 additions & 1 deletion optimus_widgetbook/lib/components/forms/selection_card.dart
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

0 comments on commit ba0c400

Please sign in to comment.