最喜欢的图标不会在颤音中使用getx进行更新
//屏幕代码 listView.builder( 物理:const noterscrollablesscrollphysics(), 缩水:是的, 填充:edgeinsets.zero, ScrolDirection:axis.tertical, itemCount:controller.favdestinationlist.length, itembuilder :( buildContext上下文,int index){ 返回容器( 宽度:MediaQuery .of(上下文) 。尺寸 .Width * 0.9, 孩子:行( 孩子们: [
IconButton(
icon:FaIcon(controller.favDestinationList[index].isfav?
FontAwesomeIcons.solidHeart : FontAwesomeIcons.heart,
color: secondaryHeaderColor,),
onPressed: () {
controller.changeStatus(
controller.favDestinationList[index].isfav);
print(controller.favDestinationList[index].isfav);
},
);
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(controller.favDestinationList[index].name),
)
]
,
)
,
);
}
),
///////code of the screen
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
itemCount: controller.favDestinationList.length,
itemBuilder: (BuildContext context, int index) {
return Container(
width: MediaQuery
.of(context)
.size
.width * 0.9,
child: Row(
children: [
IconButton(
icon:FaIcon(controller.favDestinationList[index].isfav?
FontAwesomeIcons.solidHeart : FontAwesomeIcons.heart,
color: secondaryHeaderColor,),
onPressed: () {
controller.changeStatus(
controller.favDestinationList[index].isfav);
print(controller.favDestinationList[index].isfav);
},
);
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(controller.favDestinationList[index].name),
)
]
,
)
,
);
}
),
/////////////////controller class
class SearchFavoriteController extends GetxController{
var favDestinationList=[].obs;
@override
void onInit() {
// TODO: implement onInit
super.onInit();
getFavDestination();
}
getFavDestination() async{
try{
var destination=await Api().getfavdestinations();//call api
favDestinationList.assignAll(destination);
}catch(e){
Get.snackbar('title', e.toString());
}
}
changeStatus(bool isfavorite) {
isfavorite = !isfavorite;
update();
}
}
/////////////api
List<FavoriteModel> getfavdestinations() {
return [
FavoriteModel( id: '1',name: 'Germany', isfav: false),
FavoriteModel( id: '2',name: 'Turkey', isfav: true),
FavoriteModel( id: '3',name: 'Jordan', isfav: false),
FavoriteModel( id: '4',name: 'London', isfav: false)
].obs;
}
//code of the screen
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
itemCount: controller.favDestinationList.length,
itemBuilder: (BuildContext context, int index) {
return Container(
width: MediaQuery
.of(context)
.size
.width * 0.9,
child: Row(
children: [
IconButton(
icon:FaIcon(controller.favDestinationList[index].isfav?
FontAwesomeIcons.solidHeart : FontAwesomeIcons.heart,
color: secondaryHeaderColor,),
onPressed: () {
controller.changeStatus(
controller.favDestinationList[index].isfav);
print(controller.favDestinationList[index].isfav);
},
);
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(controller.favDestinationList[index].name),
)
]
,
)
,
);
}
),
///////code of the screen
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
itemCount: controller.favDestinationList.length,
itemBuilder: (BuildContext context, int index) {
return Container(
width: MediaQuery
.of(context)
.size
.width * 0.9,
child: Row(
children: [
IconButton(
icon:FaIcon(controller.favDestinationList[index].isfav?
FontAwesomeIcons.solidHeart : FontAwesomeIcons.heart,
color: secondaryHeaderColor,),
onPressed: () {
controller.changeStatus(
controller.favDestinationList[index].isfav);
print(controller.favDestinationList[index].isfav);
},
);
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(controller.favDestinationList[index].name),
)
]
,
)
,
);
}
),
/////////////////controller class
class SearchFavoriteController extends GetxController{
var favDestinationList=[].obs;
@override
void onInit() {
// TODO: implement onInit
super.onInit();
getFavDestination();
}
getFavDestination() async{
try{
var destination=await Api().getfavdestinations();//call api
favDestinationList.assignAll(destination);
}catch(e){
Get.snackbar('title', e.toString());
}
}
changeStatus(bool isfavorite) {
isfavorite = !isfavorite;
update();
}
}
/////////////api
List<FavoriteModel> getfavdestinations() {
return [
FavoriteModel( id: '1',name: 'Germany', isfav: false),
FavoriteModel( id: '2',name: 'Turkey', isfav: true),
FavoriteModel( id: '3',name: 'Jordan', isfav: false),
FavoriteModel( id: '4',name: 'London', isfav: false)
].obs;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题不是很清楚,您必须重新提示它
但是,我认为您认为没有任何观察者小部件或getxbuilder
尝试将listView.builder与其中之一包装,它应该有效
Your question is not very clear, and you have to Rephrase it
However, i think there isn't any Observer Widget or GetXBuilder in your view
try to wrap the listView.Builder with one of them, it should works
您的问题不是很清楚,但是您可以尝试使用此功能,将您的listView用OBX小部件或列从身体开始的位置包装
Your question is not very clear, But you can try this hope this works wrap your Listview with Obx widget or Column from where body starts