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 StoreUserEmail(private val context: Context) { | |
// to make sure there's only one instance | |
companion object { | |
private val Context.dataStoree: DataStore<Preferences> by preferencesDataStore("userEmail") | |
val USER_EMAIL_KEY = stringPreferencesKey("user_email") | |
} | |
//get the saved email | |
val getEmail: Flow<String?> = context.dataStoree.data |
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
// Preferences DataStore (SharedPreferences like APIs) | |
dependencies { | |
implementation "androidx.datastore:datastore-preferences:1.0.0" | |
// optional - RxJava2 support | |
implementation "androidx.datastore:datastore-preferences-rxjava2:1.0.0" | |
// optional - RxJava3 support | |
implementation "androidx.datastore:datastore-preferences-rxjava3:1.0.0" | |
} |
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
@Composable | |
fun LoginSCreen() { | |
//context | |
val context = LocalContext.current | |
// a coroutine scope | |
val scope = rememberCoroutineScope() | |
// we instantiate the saveEmail class | |
val dataStore = StoreUserEmail(context) | |
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
val userEmail = dataStore.getEmail.collectAsState(initial = "") | |
Text(text = userEmail.value!!) |
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
sealed class Screen(val route: String?, val title: String?, val icon: ImageVector?) { | |
object PickUp : Screen("pickup", "PickUp", Icons.Default.ShoppingCart) | |
object Profile : Screen("profile", "Profile", Icons.Default.Person) | |
object Camera:Screen("camera",null,null) | |
} |
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
@ExperimentalComposeUiApi | |
@Composable | |
fun ShowKeyboard() { | |
val keyboardController = LocalSoftwareKeyboardController.current | |
var value by remember { mutableStateOf("") } | |
Column( | |
modifier = Modifier.fillMaxSize(), | |
verticalArrangement = Arrangement.Center | |
) { |
OlderNewer