123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- 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<CustomInfoCard> createState() => _CustomInfoCardState();
- }
-
- class _CustomInfoCardState extends State<CustomInfoCard> {
- late bool _isFavorite;
-
- @override
- void initState() {
- super.initState();
- _isFavorite = widget.isFavorite;
- if (!widget.isFavorite) _loadFavorite();
- }
-
- Future<void> _loadFavorite() async {
- final prefs = await SharedPreferences.getInstance();
- setState(() {
- _isFavorite = prefs.getBool('fav_${widget.title}') ?? false;
- });
- }
-
- Future<void> _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,
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
|