123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import 'package:flutter/material.dart';
- import 'package:shared_preferences/shared_preferences.dart';
-
- class DetailPage extends StatefulWidget {
- final String title;
- final String texto;
- final String categoria;
- final String imagePath;
-
- const DetailPage({
- super.key,
- required this.title,
- required this.texto,
- required this.categoria,
- this.imagePath = 'assets/icons/default_icon.jpg',
- });
-
- @override
- State<DetailPage> createState() => _DetailPageState();
- }
-
- class _DetailPageState extends State<DetailPage> {
- bool _isFavorite = false; // Inicializado con valor por defecto
-
- @override
- void initState() {
- super.initState();
- _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 Scaffold(
- appBar: AppBar(
- flexibleSpace: Padding(
- padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top - 20),
- child: Image.asset('assets/header_image.png', fit: BoxFit.cover),
- ),
- toolbarHeight: MediaQuery.of(context).size.height * 0.19,
- title: Text(
- widget.categoria,
- style: const TextStyle(color: Colors.white, fontSize: 16),
- ),
- actions: [
- IconButton(
- icon: Icon(
- _isFavorite ? Icons.favorite : Icons.favorite_border,
- color: _isFavorite ? Colors.red : Colors.white,
- ),
- onPressed: _toggleFavorite,
- ),
- ],
- ),
- body: Container(
- decoration: const BoxDecoration(color: Color.fromARGB(255, 254, 242, 221)),
- child: Padding(
- padding: const EdgeInsets.all(16.0),
- child: SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- Container(
- width: 80,
- height: 80,
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(40),
- ),
- child: ClipRRect(
- borderRadius: BorderRadius.circular(40),
- child: Image.asset(
- widget.imagePath,
- fit: BoxFit.cover,
- ),
- ),
- ),
- const SizedBox(width: 16),
- Expanded(
- child: Text(
- widget.title,
- style: const TextStyle(
- fontSize: 20,
- fontWeight: FontWeight.bold,
- color: Colors.black87,
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 20),
- Container(
- padding: const EdgeInsets.all(16),
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(12),
- ),
- child: Text(
- widget.texto,
- style: const TextStyle(fontSize: 16, height: 1.5),
- textAlign: TextAlign.justify,
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- );
- }
- }
|