GetX状态管理Flutter不改变值
我有非 obs 有状态类,它返回数据列表
Class OvertimeDetails extends StatefulWidget {
List<DataGetOvertime> listSelectedOT = [];
bool isLongPressEnable = false;
final String jenisPermit;
Function() refreshState;
OvertimeDetails(
{Key key,
this.jenisPermit,
this.listSelectedOT,
this.isLongPressEnable,
this.refreshState})
: super(key: key);
@override
_ListOvertimeState createState() => _ListOvertimeState();
}
,然后我将其作为 Rx() 调用到父类,
Rx<OvertimeDetails> listOvertimeDet;
void initState(){
listOvertimeDet = OvertimeDetails(
jenisPermit: widget.jenisPermit,
isLongPressEnable: _isLongPressEnabled,
listSelectedOT: []).obs;
}
我想通过在应用程序栏上显示它来监听 OvertimeDetails 中选定列表的值更改,如下所示,但它不起作用。但是,当我从列表中选择数据后按一次热重载时,它可以正常工作,在该值正确收听后。
Obx(
() => Text(listOvertimeDet.value.listSelectedOT == null
? "Multiple Approve"
: "${listOvertimeDet.value.listSelectedOT.length} item selected"),
)
I have non obs stateful class that return list of data
Class OvertimeDetails extends StatefulWidget {
List<DataGetOvertime> listSelectedOT = [];
bool isLongPressEnable = false;
final String jenisPermit;
Function() refreshState;
OvertimeDetails(
{Key key,
this.jenisPermit,
this.listSelectedOT,
this.isLongPressEnable,
this.refreshState})
: super(key: key);
@override
_ListOvertimeState createState() => _ListOvertimeState();
}
then I call it to the parent class as Rx()
Rx<OvertimeDetails> listOvertimeDet;
void initState(){
listOvertimeDet = OvertimeDetails(
jenisPermit: widget.jenisPermit,
isLongPressEnable: _isLongPressEnabled,
listSelectedOT: []).obs;
}
I want to listen value change of selected list from OvertimeDetails by show it on app bar like this and it didn't work. But, it work properly when I press hot reload once after I selected the data from list, after that value listen correctly.
Obx(
() => Text(listOvertimeDet.value.listSelectedOT == null
? "Multiple Approve"
: "${listOvertimeDet.value.listSelectedOT.length} item selected"),
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)