Skip to content

Instantly share code, notes, and snippets.

View RaheemJnr's full-sized avatar
🎯
Focusing

Raheem Jnr RaheemJnr

🎯
Focusing
View GitHub Profile
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
@RaheemJnr
RaheemJnr / datastoreDependencies.kt
Last active October 4, 2021 07:19
datastore example
// 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"
}
@Composable
fun LoginSCreen() {
//context
val context = LocalContext.current
// a coroutine scope
val scope = rememberCoroutineScope()
// we instantiate the saveEmail class
val dataStore = StoreUserEmail(context)
val userEmail = dataStore.getEmail.collectAsState(initial = "")
Text(text = userEmail.value!!)
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)
}
/items for bottom nav
val items = listOf(
Screen.PickUp,
Screen.Profile
)
@Composable
fun MainScreenNavigation(navController: NavHostController) {
NavHost(navController, startDestination = Screen.Profile.route!!) {
//profile
composable(Screen.Profile.route) {
// ProfileScreen()
}
//pickUp
@Composable
fun BottomNav(navController: NavController) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination
BottomNavigation(
modifier = Modifier
.padding(12.dp, 0.dp, 12.dp, 0.dp)
.height(100.dp),
//backgroundColor = Color.White,
elevation = 0.dp
@Composable
fun BottomBarWithFabDem() {
val navController = rememberNavController()
Scaffold(
bottomBar = {
BottomAppBar(
modifier = Modifier
.height(65.dp)
.clip(RoundedCornerShape(15.dp, 15.dp, 0.dp, 0.dp)),
cutoutShape = CircleShape,
@ExperimentalComposeUiApi
@Composable
fun ShowKeyboard() {
val keyboardController = LocalSoftwareKeyboardController.current
var value by remember { mutableStateOf("") }
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center
) {