- A
KeyValidationStateenum (Idle / Checking / Valid / Invalid) is cleaner than booleans โ the Composewhenbecomes exhaustive, and there's no ambiguousisLoading + isErrorcombination state - Hilt auto-provides concrete
@Singletonclasses but not interfaces โ you need@Provides fun bindFoo(impl: FooImpl): FooInterface = implin a module to inject by interface - Always save the key to storage even if validation fails โ the user might have a quota limit or a timeout, not a wrong key
?.trim()?.takeIf { it.isNotBlank() } ?: returnis a clean one-liner to guard against empty/blank input before triggering async work- For testing: extract any network dependency into an interface, implement a
FakeFoowith a pre-configured result, and the ViewModel tests run with no network and no Android context AnchoredDraggableState.requireOffset()crashes withIllegalStateExceptionif called during composition โ anchors are set inSideEffect(after composition), so the offset isn't ready yet; fix: usestate.offset.takeIf { !it.isNaN() } ?: 0ffor composition-phase reads, and callrequireOffset()only insideModifier.offset { }which runs during layout
๐ Today I Learned
API Key Validation UX in Android Settings
ยท1 min readยท#today-i-learned#android#kotlin#hilt#testing#compose