上篇提到雖然說現在軟體已經到了堪用的程度,但距離順暢使用還有很大距離
因為通常是由底下的按鍵切換的,所以在這邊可以只在由底部按鍵進入時重設
但我不建議這樣弄,他會大量增加設計的難維護度,所以也可以考慮通過路徑參數傳遞
composable("taskInputPage/{isUpdate}") { navBackStackEntry ->
val isUpdate = navBackStackEntry.arguments?.getString("isUpdate").toBoolean()
TaskInputPage(
navController = navController,
globalViewModel,
isUpdate = isUpdate
)
}
由於專案較小,我偷懶,在bottombar的onclick中加入
if (item.route == Screens.Input.route) globalVM.resetUpdate()
其實回退的設計很簡單,只需要加一個button再配上往回函數就好
由於LazyColumn是置中的,所以我需要一個Row搭配Spacer讓按鈕靠左
item {
Row(
modifier = Modifier.fillMaxWidth(0.85f),
verticalAlignment = Alignment.CenterVertically,
) {
Button(
onClick = {navController.popBackStack() },
) { Icon(Icons.AutoMirrored.Default.ArrowBack, "Back") }
Spacer(modifier = Modifier.weight(1f))
}
}
再Android裡有兩種方式可以叫dialog,但我這次會用比較土法的,另外一種可以將dialog寫在路徑中,用navController呼叫
var showDialog by remember { mutableStateOf(false) }
if (showDialog) {
AlertDialog(
onDismissRequest = { showDialog = false },
confirmButton = {
TextButton(onClick = { showDialog = false }) {
Text("OK")
}
},
title = { Text("完成") },
text = { Text("你的待辦已經新增成功!") }
)
}
然後在submit那邊修改showDialog的值
現在只能選取,不能夠新增
我選擇開啟TextField的輸入功能,讓他在按下的第二下可以變成輸入模式
// DropDownSelector
TextField(
value = currentDisplay,
onValueChange = {
onChosen(it)
},
readOnly = false,
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded) },
modifier = Modifier
.menuAnchor(MenuAnchorType.PrimaryNotEditable)
.fillMaxWidth(0.8f),
singleLine = true,
label = {
Text("Group name")
}
)
現在要來設計setting的UI介面,但暫時還不用理會互動與參數顯示
現在只有一個setting功能,就是完成的任務排最後
LazyColumn(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
item {
Row(
modifier = Modifier.fillMaxWidth(0.85f),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceAround
) {
Text("完成的排最後")
Switch(
checked = true,
onCheckedChange = null
)
}
}
}
到這邊整個專案就只剩下資料維持了,但也不會就只講這些,也會講一些比較沒有在本專案需要用的功能