Md Sohail
03/08/2024, 10:19 AMMd Sohail
03/08/2024, 10:54 AMZoltan Demant
03/08/2024, 1:01 PMJoel Denke
03/08/2024, 1:14 PMJasjeet Singh
03/08/2024, 2:36 PMclass AppPreferences(context: Context)
.
2. You can use this library with datastore to make things easier for use and future testing as well. This an example of how it is used with datastore.
3. Now that you have your preferences class setup, define a theme preference in it.
4. Inject the Apppreferences
into your MainActivity
and pass the instance to when you will call your theme composable.
@Inject
lateinit var appPreferences: AppPreferences
...
setContent {
YourAppsTheme(appPreferences) { ... }
}
1. Inside your theme, use the app preferences to get theme preference. If you are using the suggested lib, it should be very easy:
@Composable
fun YourAppsTheme(appPreferences: AppPreferences) {
val theme by appPreferences.theme.getFlow().collectAsState()
// Use theme however you want!
}
Md Sohail
03/09/2024, 9:59 AM