//屏幕代码ListView. builder(物理:const NeverScrollableScroll物理(),收缩:真,填充:EdgeInsets.zero,scrollDirection:Axis.垂直,itemCount:控制器。
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;
}
你的问题不是很清楚,你必须重新表述它然而,我认为在你的视图中没有任何观察者小部件或GetXBuilder尝试用其中一个包装listView. Builder,它应该可以工作
你的问题不是很清楚,但你可以试试这个希望这个作品包装你的Listview与Obx小部件或列从哪里主体开始