-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappsV1.dart
110 lines (96 loc) · 2.4 KB
/
appsV1.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import 'dart:io';
List<String> modelList = [];
void main(List<String> args) {
bool theCondition = true;
while (theCondition) {
line();
print("--- Aplikasi to-do list ---");
print("1. Tambah List : ");
print("2. Lihat List : ");
print("3. Delete List");
print("4. Update List");
print("5. Quit");
print("1/2/3/4 : ");
line();
stdout.write("Input Pilihan : ");
int theSelection = int.parse(stdin.readLineSync()!);
switch (theSelection) {
case 1:
addModelList();
break;
case 2:
showAllModelList();
break;
case 3:
line();
bool isSuccessDeleted = removeToDoList(findToDoList());
if (isSuccessDeleted) {
print("Sukses menghapus to-do list");
} else {
print("Gagal menghapus to-do list");
}
break;
case 4:
line();
bool isSuccessUpdated = updateToDoList();
if (isSuccessUpdated) {
print("Berhasil mengupdate to-do list");
} else {
print("Gagal Mengupdate to-do list");
}
break;
case 5:
line();
print("Application Stopped");
theCondition = false;
break;
}
}
}
void line() {
print("-------------------");
}
void addModelList() {
stdout.write("Masukan to-do list : ");
String theTodoList = stdin.readLineSync()!;
modelList.add(theTodoList);
}
void showAllModelList() {
line();
print("Menu melihat to-do list");
line();
for (int i = 0; i < modelList.length; i++) {
print('${(i + 1)} : ${modelList[i]}');
}
}
bool removeToDoList(String theTodoList) {
bool isSuccess = false;
for (int i = 0; i < modelList.length; i++) {
if (modelList[i] == theTodoList) {
modelList.removeAt(i);
isSuccess = true;
break;
}
}
return isSuccess;
}
bool updateToDoList() {
bool isSuccess = false;
stdout.write("Masukan to-do list yang ingin di update : ");
String theTodoListFind = stdin.readLineSync()!;
stdout.write("Update to-do list : ");
String theTodoListUpdate = stdin.readLineSync()!;
for (int i = 0; i < modelList.length; i++) {
if (modelList[i] == theTodoListFind) {
modelList[i] = theTodoListUpdate;
isSuccess = true;
break;
}
}
return isSuccess;
}
String findToDoList() {
stdout.write("Masukan to-do list : ");
String theTodoList = stdin.readLineSync()!;
return theTodoList;
}