add enable

This commit is contained in:
jyuesong
2022-01-13 18:50:54 +08:00
parent 6555031948
commit 51b745af19
5 changed files with 53 additions and 4 deletions

View File

@@ -156,7 +156,7 @@ class TaskItemCell extends StatelessWidget {
],
),
child: Container(
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.searchBarBg() : Colors.transparent,
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent,
padding: const EdgeInsets.symmetric(
horizontal: 15,
vertical: 8,
@@ -310,6 +310,7 @@ class TaskItemCell extends StatelessWidget {
child: Text(bean.isDisabled! == 1 ? "启用" : "禁用"),
onPressed: () {
Navigator.pop(context);
enableTask();
},
),
CupertinoActionSheetAction(
@@ -331,6 +332,10 @@ class TaskItemCell extends StatelessWidget {
);
}
void enableTask() {
ref.read(taskProvider).enableTask(bean.sId!, bean.isDisabled!);
}
void pinTask() {
ref.read(taskProvider).pinTask(bean.sId!, bean.isPinned!);
}

View File

@@ -108,4 +108,28 @@ class TaskViewModel extends BaseViewModel {
}
}
}
void enableTask(String sId, int isDisabled) async {
if (isDisabled == 0) {
HttpResponse<NullResponse> response = await Api.disableTask(sId);
if (response.success) {
list.firstWhere((element) => element.sId == sId).isDisabled = 1;
sortList();
success();
} else {
failToast(response.message, notify: true);
}
} else {
HttpResponse<NullResponse> response = await Api.enableTask(sId);
if (response.success) {
list.firstWhere((element) => element.sId == sId).isDisabled = 0;
sortList();
success();
} else {
failToast(response.message, notify: true);
}
}
}
}