Skip to content

Commit

Permalink
refactor: Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
witwash committed Oct 15, 2024
1 parent 24ba738 commit c0fdf08
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions optimus/lib/src/button/base_button_variant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:optimus/src/theme/optimus_tokens.dart';
enum BaseButtonVariant { primary, secondary, tertiary, ghost, danger, success }

extension ColorScheme on BaseButtonVariant {
// TODO(witwash): split and rework, possibly using WidgetStates
// ignore: avoid-high-cyclomatic-complexity, ignore until reworked
Color? getBackgroundColor(
OptimusTokens tokens, {
required bool isEnabled,
Expand Down Expand Up @@ -105,6 +107,8 @@ extension ColorScheme on BaseButtonVariant {
}
}

// TODO(witwash): split and rewrite, possibly using WidgetState
// ignore: avoid-high-cyclomatic-complexity, ignore until reworked
Color getBadgeTextColor(
OptimusTokens tokens, {
required bool isEnabled,
Expand Down
10 changes: 6 additions & 4 deletions optimus/lib/src/form/date_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,31 @@ class DateFormatter extends TextInputFormatter {
/// empty space will be filled with the placeholder
/// result = '23-05-201Y'
@override
// TODO(witwash): rewrite and split in chunks
// ignore: avoid-high-cyclomatic-complexity, I'll split it in chunks
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
final oldSelection = oldValue.selection;
final oldText = oldValue.text;
final newText = newValue.text;
final oldSelectionStart = oldValue.selection.start;
final oldSelectionStart = oldSelection.start;
final newSelectionStart = newValue.selection.start;

String resultText = oldText;
int resultSelection = oldSelectionStart;

if (oldValue.text.isEmpty) {
if (oldText.isEmpty) {
if (newText.clean().isEmpty) return oldValue;

return _pasteStarting(placeholder, 0, placeholder.length, newText);
} else if (oldSelection.end - oldSelection.start >= 1) {
} else if (oldSelection.end - oldSelectionStart >= 1) {
return _pasteStarting(
oldText,
oldSelectionStart,
oldSelection.end,
newText.substring(oldSelection.start, newValue.selection.end),
newText.substring(oldSelectionStart, newValue.selection.end),
);
}

Expand Down
2 changes: 1 addition & 1 deletion optimus/lib/src/form/input_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class _OptimusInputFieldState extends State<OptimusInputField>
caption: widget.caption,
captionIcon: widget.captionIcon,
helperMessage: widget.helperMessage,
error: widget.error,
error: error,
errorVariant: widget.errorVariant,
hasBorders: widget.hasBorders,
isRequired: widget.isRequired,
Expand Down
4 changes: 2 additions & 2 deletions optimus/lib/src/form/input_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ class _InputFormFieldState extends FormFieldState<String> {
final oldWidgetController = oldWidget.controller;
final widgetController = widget.controller;

if (oldWidgetController != null && widget.controller == null) {
if (oldWidgetController != null && widgetController == null) {
_controller =
TextEditingController.fromValue(oldWidgetController.value);
}
if (widgetController != null) {
setValue(widgetController.text);
if (oldWidget.controller == null) _controller = null;
if (oldWidgetController == null) _controller = null;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion optimus/lib/src/form/multiselect_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class _OptimusMultiSelectInputFieldState extends State<MultiSelectInputField>
caption: widget.caption,
captionIcon: widget.captionIcon,
helperMessage: widget.helperMessage,
error: widget.error,
error: error,
errorVariant: widget.errorVariant,
isRequired: widget.isRequired,
prefix: prefix,
Expand Down
2 changes: 1 addition & 1 deletion optimus/lib/src/icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class OptimusIcon extends StatelessWidget {
iconData,
color: colorOption?.let((option) => option.toIconColor(tokens)) ??
tokens.textStaticPrimary,
size: _getIconSize(context.tokens),
size: _getIconSize(tokens),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion optimus/lib/src/progress_indicator/progress_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class _VerticalProgressIndicatorState extends State<_VerticalProgressIndicator>
Widget build(BuildContext context) {
final bool isClosed = !_isExpanded && _animationController.isDismissed;
final items = widget.items;
final headerItem = _isExpanded ? widget.items.first : _currentItem;
final headerItem = _isExpanded ? items.first : _currentItem;

final Widget result = Offstage(
offstage: isClosed,
Expand Down
2 changes: 1 addition & 1 deletion optimus/lib/src/select_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class _Chevron extends StatelessWidget {

return Icon(
OptimusIcons.chevron_down,
size: context.tokens.sizing300,
size: tokens.sizing300,
color: isEnabled ? tokens.textStaticPrimary : tokens.textDisabled,
);
}
Expand Down

0 comments on commit c0fdf08

Please sign in to comment.