这里存在:
我的问题控制器
Rx<GitlabIssue> selectedIssue = new GitlabIssue().obs;
RxList<GitlabIssue> issues = <GitlabIssue>[].obs;
void changeIssueState(GitlabIssueState state) async {
var stateValue = _getGitLabIssueStateValue(state);
bool isInternet = await Utils().isInternet();
if (isInternet) {
var resp = await _issueProvider.changeGitlabIssueState(
projectId, selectedIssue.value.iid, stateValue);
if (resp.statusCode == 200) {
Get.snackbar(
'Issue state changed',
'Issue is $stateValue',
);
var issueIndex = issues.indexOf(selectedIssue.value);
selectedIssue.value.state =
selectedIssue.value.state == 'opened' ? 'closed' : 'opened';
issues[issueIndex] = selectedIssue.value;
gitLabIssueBox.put(projectId, issues);
} else
Get.snackbar(
'Issue state not changed', 'Issue state was not correctly changed');
} else
print('No connectivity');
}
我的观点
Widget _getButtonStatus() {
return Obx(() {
Color stateColor = _issueController.selectedIssue.value.state == 'closed'
? Colors.green
: Colors.red;
return OutlinedButton(
onPressed: () {
_issueController.selectedIssue.value.state == 'closed'
? _issueController.changeIssueState(GitlabIssueState.reopen)
: _issueController.changeIssueState(GitlabIssueState.close);
},
style: OutlinedButton.styleFrom(
//primary: Colors.white,
//backgroundColor: Colors.teal,
side: BorderSide(color: stateColor, width: 1),
),
child: Obx(
() => Text(
_issueController.selectedIssue.value.state == 'closed'
? 'Reopen issue'
: 'Close issue',
style: TextStyle(color: stateColor),
),
),
);
});
}
我更新了 selectedIssue.obs 的值,并将小部件放入 Obx() => 函数中。
我不知道为什么我的小部件不重绘。
奇怪的是,我的 onPressed 函数表现正确;该按钮保持不变,但如果我再次单击它,我的问题状态会正确更改。
请帮我 !!:D