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,
});
...
}
Improve enum value names. The names are not meaningful.
TUIMenuItemProperties
as a separate class when it is only going to be used inTUIMenuItem
as an argument. Instead, we can just take all properties ofTUIMenuItemProperties
inside theTUIMenuItem
constructor directly. This will make the calling side simple as they do not have to create an instance ofTUIMenuItemProperties
every time they create an instance ofTUIMenuItem
Change this.
To this.