Работает добавление

This commit is contained in:
Максим 2023-11-23 15:31:34 +03:00
parent 36c001ca2e
commit 96d09edf51
2 changed files with 7 additions and 6 deletions

View File

@ -50,7 +50,7 @@ fun ScreenListProduct(
Column( Column(
modifier = Modifier.fillMaxHeight().padding(bottom = 65.dp) modifier = Modifier.fillMaxHeight().padding(bottom = 65.dp)
) { ) {
//FormNewProduct(bicycleViewModel, navHostController) FormNewProduct(bicycleViewModel, navHostController)
LazyColumn { LazyColumn {
itemsIndexed(bicycles) { index, item -> itemsIndexed(bicycles) { index, item ->
ListProduct( ListProduct(

View File

@ -28,7 +28,10 @@ import com.example.labwork.viewmodel.BicycleViewModel
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Composable @Composable
fun FormNewProduct(bicycleDao: BicycleDao, navHostController: NavHostController) { fun FormNewProduct(
bicycleViewModel: BicycleViewModel,
navHostController: NavHostController
) {
val isFormVisible = remember { mutableStateOf(false) } val isFormVisible = remember { mutableStateOf(false) }
var brand by remember { mutableStateOf("") } var brand by remember { mutableStateOf("") }
var model by remember { mutableStateOf("") } var model by remember { mutableStateOf("") }
@ -96,10 +99,8 @@ fun FormNewProduct(bicycleDao: BicycleDao, navHostController: NavHostController)
.fillMaxWidth() .fillMaxWidth()
.padding(9.dp), .padding(9.dp),
onClick = { onClick = {
GlobalScope.launch {
val newBicycle = Bicycle(null, brand, model, color, null) val newBicycle = Bicycle(null, brand, model, color, null)
bicycleDao.insertBicycle(newBicycle) bicycleViewModel.insertBicycle(newBicycle)
}
isFormVisible.value = false isFormVisible.value = false
navHostController.navigate("ListProduct") navHostController.navigate("ListProduct")
}, },