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

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(
modifier = Modifier.fillMaxHeight().padding(bottom = 65.dp)
) {
//FormNewProduct(bicycleViewModel, navHostController)
FormNewProduct(bicycleViewModel, navHostController)
LazyColumn {
itemsIndexed(bicycles) { index, item ->
ListProduct(

View File

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