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

Refactor TUIMenuItem #71

Open
kalpeshp0310 opened this issue May 2, 2024 · 0 comments
Open

Refactor TUIMenuItem #71

kalpeshp0310 opened this issue May 2, 2024 · 0 comments

Comments

@kalpeshp0310
Copy link
Member

  1. Why abstract TUIMenuItemProperties as a separate class when it is only going to be used in TUIMenuItem as an argument. Instead, we can just take all properties of TUIMenuItemProperties inside the TUIMenuItem constructor directly. This will make the calling side simple as they do not have to create an instance of TUIMenuItemProperties every time they create an instance of TUIMenuItem

Change this.

class TUIMenuItemProperties {
  late String title;
  late TUIMenuItemStyle style;
  late TUIMenuItemState state;

  TUIMenuItemProperties({
    required this.title,
    required this.style,
    this.state = TUIMenuItemState.unchecked,
  });
}

class TUIMenuItem extends StatefulWidget {
  final TUIMenuItemProperties item;
  final bool backgroundDark; // for hover
  final Function(TUIMenuItemState)? action;
  final Function(TUIMenuItemState)? onLeftTap;
  final Function(TUIMenuItemState)? onRightTap;

  const TUIMenuItem({
    super.key,
    required this.item,
    this.backgroundDark = false,
    this.onLeftTap,
    this.onRightTap,
    this.action,
  });

 ...
}

To this.

class TUIMenuItem extends StatefulWidget {
  final String title;
  final TUIMenuItemStyle style;
  final TUIMenuItemState state;
  final bool backgroundDark; // for hover
  final Function(TUIMenuItemState)? action;
  final Function(TUIMenuItemState)? onLeftTap;
  final Function(TUIMenuItemState)? onRightTap;

  const TUIMenuItem({
    super.key,
    required this.title,
    required this.style,
    this.state = TUIMenuItemState.unchecked,
    this.backgroundDark = false,
    this.onLeftTap,
    this.onRightTap,
    this.action,
  });

 ...
}
  1. Improve enum value names. The names are not meaningful.
enum TUIMenuItemStyle {
  none(0),
  onlyLeft(1),
  onlyRight(2),
  both(3);

  const TUIMenuItemStyle(this.value);

  final num value;

  static TUIMenuItemStyle getByValue(num i) {
    return TUIMenuItemStyle.values.firstWhere((x) => x.value == i);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant