Skip to content

Commit

Permalink
refactor: Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
witwash committed Nov 14, 2023
1 parent 78081d5 commit 9975417
Show file tree
Hide file tree
Showing 42 changed files with 485 additions and 429 deletions.
2 changes: 1 addition & 1 deletion optimus/lib/src/banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class OptimusBanner extends StatelessWidget {
top: spacing100,
right: spacing100,
child: OptimusIconButton(
onPressed: () => onDismiss,
onPressed: onDismiss,
icon: const Icon(OptimusIcons.cross_close),
size: OptimusWidgetSize.small,
variant: OptimusButtonVariant.ghost,
Expand Down
88 changes: 45 additions & 43 deletions optimus/lib/src/button/base_dropdown_button.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:optimus/optimus.dart';
import 'package:optimus/src/button/common.dart';
import 'package:optimus/src/common/gesture_wrapper.dart';
import 'package:optimus/src/overlay_controller.dart';
import 'package:optimus/src/typography/presets.dart';

Expand Down Expand Up @@ -64,6 +65,12 @@ class _BaseDropDownButtonState<T> extends State<BaseDropDownButton<T>>

void _onFocusChanged() => setState(() {});

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

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

bool get _isEnabled => widget.onItemSelected != null;

Color get _textColor => widget.variant.toButtonVariant().foregroundColor(
Expand Down Expand Up @@ -106,51 +113,46 @@ class _BaseDropDownButtonState<T> extends State<BaseDropDownButton<T>>
onHidden: _controller.reverse,
child: IgnorePointer(
ignoring: !_isEnabled,
child: MouseRegion(
onEnter: (_) => setState(() => _isHovered = true),
onExit: (_) => setState(() => _isHovered = false),
child: GestureDetector(
onTap: _node.requestFocus,
onTapDown: (_) => setState(() => _isPressed = true),
onTapUp: (_) => setState(() => _isPressed = false),
onTapCancel: () => setState(() => _isPressed = false),
child: Focus(
focusNode: _node,
child: SizedBox(
height: widget.size.value,
child: AnimatedContainer(
padding: const EdgeInsets.symmetric(horizontal: spacing200),
key: _selectFieldKey,
decoration: BoxDecoration(
color: _color,
borderRadius: widget.borderRadius,
border: borderColor != null
? Border.all(color: borderColor, width: 1)
: null,
),
duration: buttonAnimationDuration,
curve: buttonAnimationCurve,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (child != null)
Padding(
padding: const EdgeInsets.only(right: 12),
child: DefaultTextStyle.merge(
style: _labelStyle,
child: child,
),
),
RotationTransition(
turns: _iconTurns,
child: Icon(
OptimusIcons.chevron_down,
size: widget.size.iconSize,
color: _textColor,
child: GestureWrapper(
onHoverChanged: _handleHoverChanged,
onPressedChanged: _handlePressedChanged,
onTap: _node.requestFocus,
child: Focus(
focusNode: _node,
child: SizedBox(
height: widget.size.value,
child: AnimatedContainer(
padding: const EdgeInsets.symmetric(horizontal: spacing200),
key: _selectFieldKey,
decoration: BoxDecoration(
color: _color,
borderRadius: widget.borderRadius,
border: borderColor != null
? Border.all(color: borderColor, width: 1)
: null,
),
duration: buttonAnimationDuration,
curve: buttonAnimationCurve,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (child != null)
Padding(
padding: const EdgeInsets.only(right: 12),
child: DefaultTextStyle.merge(
style: _labelStyle,
child: child,
),
),
],
),
RotationTransition(
turns: _iconTurns,
child: Icon(
OptimusIcons.chevron_down,
size: widget.size.iconSize,
color: _textColor,
),
),
],
),
),
),
Expand Down
63 changes: 31 additions & 32 deletions optimus/lib/src/button/icon.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:optimus/optimus.dart';
import 'package:optimus/src/button/common.dart';
import 'package:optimus/src/common/gesture_wrapper.dart';

/// When you don’t have enough space for regular buttons, or the action is
/// clear enough, you can use an icon button without text.
Expand Down Expand Up @@ -36,9 +37,12 @@ class _OptimusIconButtonState extends State<OptimusIconButton>
bool _isHovered = false;
bool _isPressed = false;

void _onHoverChanged(bool isHovering) =>
void _handleHoverChanged(bool isHovering) =>
setState(() => _isHovered = isHovering);

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

bool get _isEnabled => widget.onPressed != null;

@override
Expand All @@ -53,43 +57,38 @@ class _OptimusIconButtonState extends State<OptimusIconButton>

return IgnorePointer(
ignoring: !isEnabled,
child: MouseRegion(
onEnter: (_) => _onHoverChanged(true),
onExit: (_) => _onHoverChanged(false),
child: GestureDetector(
onTap: widget.onPressed,
onTapDown: (_) => setState(() => _isPressed = true),
onTapUp: (_) => setState(() => _isPressed = false),
onTapCancel: () => setState(() => _isPressed = false),
child: AnimatedContainer(
height: widget.size.containerSize,
width: widget.size.containerSize,
padding: EdgeInsets.zero,
decoration: BoxDecoration(
color: widget.variant.backgroundColor(
child: GestureWrapper(
onHoverChanged: _handleHoverChanged,
onPressedChanged: _handlePressedChanged,
onTap: widget.onPressed,
child: AnimatedContainer(
height: widget.size.containerSize,
width: widget.size.containerSize,
padding: EdgeInsets.zero,
decoration: BoxDecoration(
color: widget.variant.backgroundColor(
tokens,
isEnabled: _isEnabled,
isPressed: _isPressed,
isHovered: _isHovered,
),
border: borderColor != null
? Border.all(color: borderColor, width: 1)
: null,
borderRadius: const BorderRadius.all(borderRadius50),
),
duration: buttonAnimationDuration,
child: IconTheme.merge(
data: IconThemeData(
color: widget.variant.foregroundColor(
tokens,
isEnabled: _isEnabled,
isPressed: _isPressed,
isHovered: _isHovered,
),
border: borderColor != null
? Border.all(color: borderColor, width: 1)
: null,
borderRadius: const BorderRadius.all(borderRadius50),
),
duration: buttonAnimationDuration,
child: IconTheme.merge(
data: IconThemeData(
color: widget.variant.foregroundColor(
tokens,
isEnabled: _isEnabled,
isPressed: _isPressed,
isHovered: _isHovered,
),
size: widget.size.iconSize,
),
child: widget.icon,
size: widget.size.iconSize,
),
child: widget.icon,
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions optimus/lib/src/chat/optimus_chat_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class _OptimusChatInputState extends State<OptimusChatInput> {

void _handleControllerChanged() => setState(() {});

void _onTap() {
void _handleTap() {
widget.onSendPressed(_controller.text);
_controller.clear();
}
Expand All @@ -45,7 +45,7 @@ class _OptimusChatInputState extends State<OptimusChatInput> {
trailing: OptimusEnabled(
isEnabled: _isSendEnabled,
child: GestureDetector(
onTap: _onTap,
onTap: _handleTap,
child: const OptimusIcon(
iconData: OptimusIcons.send_message,
colorOption: OptimusIconColorOption.basic,
Expand Down
6 changes: 3 additions & 3 deletions optimus/lib/src/checkbox/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class OptimusCheckbox extends StatelessWidget {
return false;
}

void _onTap() {
void _handleTap() {
final newValue = isChecked ?? false;
onChanged(!newValue);
}
Expand All @@ -122,7 +122,7 @@ class OptimusCheckbox extends StatelessWidget {
child: GroupWrapper(
error: error,
child: GestureDetector(
onTap: _onTap,
onTap: _handleTap,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
Expand All @@ -134,7 +134,7 @@ class OptimusCheckbox extends StatelessWidget {
isChecked: isChecked,
isEnabled: isEnabled,
onChanged: onChanged,
onTap: _onTap,
onTap: _handleTap,
),
),
Expanded(
Expand Down
4 changes: 2 additions & 2 deletions optimus/lib/src/checkbox/checkbox_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OptimusCheckboxGroup<T> extends StatelessWidget {
/// Controls whether the whole group is enabled.
final bool isEnabled;

void _onChanged(OptimusGroupItem<T> v, bool checked) {
void _handleChanged(OptimusGroupItem<T> v, bool checked) {
if (checked) {
_values.add(v.value);
} else {
Expand All @@ -69,7 +69,7 @@ class OptimusCheckboxGroup<T> extends StatelessWidget {
size: size,
label: v.label,
isEnabled: isEnabled,
onChanged: (checked) => _onChanged(v, checked),
onChanged: (checked) => _handleChanged(v, checked),
),
)
.toList(),
Expand Down
45 changes: 22 additions & 23 deletions optimus/lib/src/checkbox/checkbox_tick.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/widgets.dart';
import 'package:optimus/optimus_icons.dart';
import 'package:optimus/src/border_radius.dart';
import 'package:optimus/src/common/gesture_wrapper.dart';
import 'package:optimus/src/theme/theme.dart';

class CheckboxTick extends StatefulWidget {
Expand All @@ -25,47 +26,45 @@ class CheckboxTick extends StatefulWidget {

class _CheckboxTickState extends State<CheckboxTick> with ThemeGetter {
bool _isHovering = false;
bool _isTappedDown = false;
bool _isPressed = false;

_TickState get _state => widget.isChecked.toState;

_InteractionState get _interactionState {
if (!widget.isEnabled) return _InteractionState.disabled;
if (_isTappedDown) return _InteractionState.active;
if (_isPressed) return _InteractionState.active;
if (_isHovering) return _InteractionState.hover;

return _InteractionState.basic;
}

void _onHoverChanged(bool hovered) => setState(() => _isHovering = hovered);
void _handleHoverChanged(bool hovered) =>
setState(() => _isHovering = hovered);

void _handlePressedChanged(bool pressed) =>
setState(() => _isPressed = pressed);

Color get _borderColor => widget.isError
? theme.tokens.backgroundInteractiveDangerDefault
: _interactionState.borderColor(context);

@override
Widget build(BuildContext context) => GestureDetector(
Widget build(BuildContext context) => GestureWrapper(
onHoverChanged: _handleHoverChanged,
onPressedChanged: _handlePressedChanged,
onTap: widget.onTap,
onTapDown: (_) => setState(() => _isTappedDown = true),
onTapUp: (_) => setState(() => _isTappedDown = false),
onTapCancel: () => setState(() => _isTappedDown = false),
child: MouseRegion(
onEnter: (_) => _onHoverChanged(true),
onExit: (_) => _onHoverChanged(false),
child: AnimatedContainer(
duration: const Duration(milliseconds: 100),
decoration: BoxDecoration(
color: _interactionState.fillColor(context, _state),
border: _state.isUnchecked
? Border.all(color: _borderColor, width: 1.5)
: null,
borderRadius: const BorderRadius.all(borderRadius25),
),
width: 16,
height: 16,
child:
_CheckboxIcon(icon: _state.icon, isEnabled: widget.isEnabled),
child: AnimatedContainer(
duration: const Duration(milliseconds: 100),
decoration: BoxDecoration(
color: _interactionState.fillColor(context, _state),
border: _state.isUnchecked
? Border.all(color: _borderColor, width: 1.5)
: null,
borderRadius: const BorderRadius.all(borderRadius25),
),
width: 16,
height: 16,
child: _CheckboxIcon(icon: _state.icon, isEnabled: widget.isEnabled),
),
);
}
Expand Down
Loading

0 comments on commit 9975417

Please sign in to comment.