I have an app that i get a list from my api. so in this list i want ti choose some object that its a favorite objects, so i want to save the selected items when i navigate back. but i choose items and when i go back and come to page again, All favorites button are empty. can you provide me some code from example? here is my code:
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1, childAspectRatio: 3 / 1.5),
itemCount: widget.item.length,
itemBuilder: (context, index) {
persist() async{
setState(() {
widget.item[index].liked = !widget.item[index].liked;
});
}
return InkWell(
onTap: (){
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => PropertyDetailsPage(),
settings: RouteSettings(
arguments: widget.item[index]
)
));
},
child: Align(
alignment: Alignment.topCenter,
child: SizedBox(
width: MediaQuery.of(context).size.width / 1.04,
height: MediaQuery.of(context).size.height / 5,
child: Container(
child: Stack(
children: [
Row(
children: [
IconButton(
onPressed:persist,
icon: Icon(
Icons.favorite,
color:widget.item[index].liked ? Colors.red : Colors.grey[500],
)),
Padding(padding: EdgeInsets.only(right: MediaQuery.of(context).size.width / 15,
)),
Text(widget.item[index].Price,
style: TextStyle(
fontFamily: "IranSans",
fontSize: MediaQuery.of(context).size.width / 22
),
),
],
),