Class SlotKey
java.lang.Object
com.ultikits.ultitools.abstracts.gui.declarative.core.SlotKey
SlotKey uniquely identifies a Widget within the Widget tree.
In lists or dynamic content, SlotKey is essential to the diff algorithm. It lets the framework recognize which Widgets are "the same one" (just with changed data) versus which were added or removed, avoiding unnecessary rebuilds.
When to use it:
- List items need a stable key to preserve state (e.g. scroll position, selection state)
- Dynamic content needs a key to trigger the correct animation or transition
- Reusing an Element improves performance
Best practice:
// Good: use a stable business identifier as the key
ListView.builder()
.children(players.stream()
.map(p -> PlayerWidget.builder()
.key(SlotKey.of(p.getUniqueId().toString())) // stable UUID
.player(p)
.build())
.toList())
.build();
// Avoid: using the list index as the key (unless the list is static)
// This makes the key mismatch the actual content once the data updates
- Since:
- 6.2.0
- Version:
- 1.0.0
- Author:
- UltiTools Team
- See Also:
-
Field Details
-
value
-
-
Constructor Details
-
SlotKey
-
-
Method Details
-
of
Creates a SlotKey.- Parameters:
value- the key value, must not be empty- Returns:
- a new SlotKey instance
- Throws:
IllegalArgumentException- if value is empty
-
of
@NotNull public static @NotNull SlotKey of(@NotNull @NotNull String prefix, @NotNull @NotNull String value) Creates a SlotKey with a prefix.- Parameters:
prefix- the prefixvalue- the key value- Returns:
- a new SlotKey instance
-
getValue
Gets the key's string value.- Returns:
- the key value
-
equals
-
hashCode
public int hashCode() -
toString
-