-
-
Save KatieBarnett/ad15425caaedea9729b377ec2fc9238a to your computer and use it in GitHub Desktop.
Custom GlanceStateDefinition - Custom GlanceStateDefinition fetching the state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuoteWidget : GlanceAppWidget(errorUiLayout = R.layout.widget_error_layout) { | |
override val stateDefinition = QuoteWidgetStateDefinition | |
override suspend fun provideGlance(context: Context, id: GlanceId) { | |
provideContent { | |
// Fetch the state | |
val widgetState = currentState<WidgetState>() | |
when (widgetState) { | |
is WidgetState.Available -> QuoteWidgetContent( | |
displayText = widgetState.quote.text, | |
topic = widgetState.topicName, | |
) | |
WidgetState.Loading -> QuoteWidgetLoading() | |
is WidgetState.Unavailable -> QuoteWidgetError( | |
message = widgetState.message, | |
) | |
} | |
// Use the state | |
... | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment