我该如何修复我的代码以使我的计数值从函数中更新

时间:2019-07-08 10:18:52

标签: flutter

如何让_handlerRadioValuegender()更新我在顶部声明为count的{​​{1}}值。

我尝试了可以​​做的事,这是所有var count = 3函数的结果。现在,它始终采用我在顶部定义的值,这意味着我的debugprint()函数对计数值没有影响。

_handler

我希望从var count = 3; int _handleRadioValuegender(int value) { setState(() { _gender = value; switch (_gender) { case 0: debugPrint('case0'); count++; debugPrint('$count'); break; case 1: debugPrint('case1'); this.count++; this.count++; debugPrint('$count'); break; } }); } String gender() { if (count == 1) { debugPrint('$count'); return 'Male'; } else if (count == 3) { debugPrint('$count'); return 'Female'; } else { debugPrint('$count'); } } 函数中更新计数值,并且当_handlerRadioValuegender()访问它时,它应该根据该值返回值。Screenshot of debugprints()

0 个答案:

没有答案