Here the existant :
My IssueController
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');
}
My view
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),
),
),
);
});
}
I update the value of my selectedIssue.obs and I put the widget in an Obx() => function.
I can't figure out why my widget doesn't redraw.
Weirdly, my onPressed function behave correctly; The button stay the same but if I click again on it the status of my issue change correctly.
Please help me !! :D
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…