import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'detail_page.dart'; class CustomInfoCard extends StatefulWidget { final String imagePath; final String title; final String subtitle; final String texto; final bool isFavorite; const CustomInfoCard({ super.key, required this.imagePath, required this.title, required this.subtitle, required this.texto, this.isFavorite = false, }); @override State createState() => _CustomInfoCardState(); } class _CustomInfoCardState extends State { late bool _isFavorite; @override void initState() { super.initState(); _isFavorite = widget.isFavorite; if (!widget.isFavorite) _loadFavorite(); } Future _loadFavorite() async { final prefs = await SharedPreferences.getInstance(); setState(() { _isFavorite = prefs.getBool('fav_${widget.title}') ?? false; }); } Future _toggleFavorite() async { final prefs = await SharedPreferences.getInstance(); setState(() { _isFavorite = !_isFavorite; prefs.setBool('fav_${widget.title}', _isFavorite); }); } @override Widget build(BuildContext context) { return GestureDetector( onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => DetailPage( title: widget.title, texto: widget.texto, ), ), ); }, child: SizedBox( width: double.infinity, height: 130, child: Stack( children: [ Card( margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(30), ), color: const Color.fromARGB(255, 254, 242, 221), child: Padding( padding: const EdgeInsets.only(right: 8), child: Row( children: [ Container( width: 90, height: 90, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(36), ), child: ClipRRect( borderRadius: BorderRadius.circular(36), child: Image.asset( widget.imagePath, fit: BoxFit.cover, width: 90, height: 90, ), ), ), const SizedBox(width: 16), Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( widget.title, style: const TextStyle( fontSize: 16, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 4), Text( widget.subtitle, style: TextStyle( fontSize: 14, color: Colors.grey[600], ), ), ], ), ), ], ), ), ), Positioned( top: 12, right: 28, child: IconButton( icon: Icon( _isFavorite ? Icons.favorite : Icons.favorite_border, color: _isFavorite ? Colors.red : Colors.grey[400], ), onPressed: _toggleFavorite, ), ), ], ), ), ); } }