Bläddra i källkod

Last CCOM3986 version

Luis Aparicio 3 dagar sedan
förälder
incheckning
ed0b7b5829
2 ändrade filer med 111 tillägg och 50 borttagningar
  1. 5
    8
      lib/custom_info_card.dart
  2. 106
    42
      lib/detail_page.dart

+ 5
- 8
lib/custom_info_card.dart Visa fil

49
           title: widget.title,
49
           title: widget.title,
50
           texto: widget.texto,
50
           texto: widget.texto,
51
           categoria: widget.categoria,
51
           categoria: widget.categoria,
52
+          imagePath: widget.imagePath,
52
         ),
53
         ),
53
       ),
54
       ),
54
     ),
55
     ),
131
 
132
 
132
   Color _getCategoryColor(String categoria) {
133
   Color _getCategoryColor(String categoria) {
133
     switch (categoria) {
134
     switch (categoria) {
134
-      case 'Actividades':
135
-        return Colors.blue;
136
-      case 'Noticias UPR':
137
-        return Colors.green;
138
-      case 'Fechas Importantes':
139
-        return Colors.purple;
140
-      default:
141
-        return Colors.grey;
135
+      case 'Actividades': return Colors.blue;
136
+      case 'Noticias UPR': return Colors.green;
137
+      case 'Fechas Importantes': return Colors.purple;
138
+      default: return Colors.grey;
142
     }
139
     }
143
   }
140
   }
144
 }
141
 }

+ 106
- 42
lib/detail_page.dart Visa fil

1
 import 'package:flutter/material.dart';
1
 import 'package:flutter/material.dart';
2
+import 'package:shared_preferences/shared_preferences.dart';
2
 
3
 
3
-class DetailPage extends StatelessWidget {
4
+class DetailPage extends StatefulWidget {
4
   final String title;
5
   final String title;
5
   final String texto;
6
   final String texto;
6
   final String categoria;
7
   final String categoria;
8
+  final String imagePath;
7
 
9
 
8
   const DetailPage({
10
   const DetailPage({
9
     super.key,
11
     super.key,
10
     required this.title,
12
     required this.title,
11
     required this.texto,
13
     required this.texto,
12
     required this.categoria,
14
     required this.categoria,
15
+    this.imagePath = 'assets/icons/default_icon.jpg',
13
   });
16
   });
14
 
17
 
15
   @override
18
   @override
16
-  Widget build(BuildContext context) => Scaffold(
17
-    appBar: AppBar(
18
-      flexibleSpace: Padding(
19
-        padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top - 20),
20
-        child: Image.asset('assets/header_image.png', fit: BoxFit.cover),
21
-      ),
22
-      toolbarHeight: MediaQuery.of(context).size.height * 0.19,
23
-      title: Text(
24
-        categoria,
25
-        style: const TextStyle(color: Colors.white, fontSize: 16),
19
+  State<DetailPage> createState() => _DetailPageState();
20
+}
21
+
22
+class _DetailPageState extends State<DetailPage> {
23
+  bool _isFavorite = false; // Inicializado con valor por defecto
24
+
25
+  @override
26
+  void initState() {
27
+    super.initState();
28
+    _loadFavorite();
29
+  }
30
+
31
+  Future<void> _loadFavorite() async {
32
+    final prefs = await SharedPreferences.getInstance();
33
+    setState(() {
34
+      _isFavorite = prefs.getBool('fav_${widget.title}') ?? false;
35
+    });
36
+  }
37
+
38
+  Future<void> _toggleFavorite() async {
39
+    final prefs = await SharedPreferences.getInstance();
40
+    setState(() {
41
+      _isFavorite = !_isFavorite;
42
+      prefs.setBool('fav_${widget.title}', _isFavorite);
43
+    });
44
+  }
45
+
46
+  @override
47
+  Widget build(BuildContext context) {
48
+    return Scaffold(
49
+      appBar: AppBar(
50
+        flexibleSpace: Padding(
51
+          padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top - 20),
52
+          child: Image.asset('assets/header_image.png', fit: BoxFit.cover),
53
+        ),
54
+        toolbarHeight: MediaQuery.of(context).size.height * 0.19,
55
+        title: Text(
56
+          widget.categoria,
57
+          style: const TextStyle(color: Colors.white, fontSize: 16),
58
+        ),
59
+        actions: [
60
+          IconButton(
61
+            icon: Icon(
62
+              _isFavorite ? Icons.favorite : Icons.favorite_border,
63
+              color: _isFavorite ? Colors.red : Colors.white,
64
+            ),
65
+            onPressed: _toggleFavorite,
66
+          ),
67
+        ],
26
       ),
68
       ),
27
-    ),
28
-    body: Container(
29
-      decoration: const BoxDecoration(color: Color.fromARGB(255, 254, 242, 221)),
30
-      child: Padding(
31
-        padding: const EdgeInsets.all(16.0),
32
-        child: SingleChildScrollView(
33
-          child: Column(
34
-            crossAxisAlignment: CrossAxisAlignment.start,
35
-            children: [
36
-              Text(
37
-                title,
38
-                style: const TextStyle(
39
-                  fontSize: 24,
40
-                  fontWeight: FontWeight.bold,
41
-                  color: Colors.black87,
42
-                ),
43
-              ),
44
-              const SizedBox(height: 8),
45
-              Container(
46
-                padding: const EdgeInsets.all(12),
47
-                decoration: BoxDecoration(
48
-                  color: Colors.white,
49
-                  borderRadius: BorderRadius.circular(8),
69
+      body: Container(
70
+        decoration: const BoxDecoration(color: Color.fromARGB(255, 254, 242, 221)),
71
+        child: Padding(
72
+          padding: const EdgeInsets.all(16.0),
73
+          child: SingleChildScrollView(
74
+            child: Column(
75
+              crossAxisAlignment: CrossAxisAlignment.start,
76
+              children: [
77
+                Row(
78
+                  children: [
79
+                    Container(
80
+                      width: 80,
81
+                      height: 80,
82
+                      decoration: BoxDecoration(
83
+                        color: Colors.white,
84
+                        borderRadius: BorderRadius.circular(40),
85
+                      ),
86
+                      child: ClipRRect(
87
+                        borderRadius: BorderRadius.circular(40),
88
+                        child: Image.asset(
89
+                          widget.imagePath,
90
+                          fit: BoxFit.cover,
91
+                        ),
92
+                      ),
93
+                    ),
94
+                    const SizedBox(width: 16),
95
+                    Expanded(
96
+                      child: Text(
97
+                        widget.title,
98
+                        style: const TextStyle(
99
+                          fontSize: 20,
100
+                          fontWeight: FontWeight.bold,
101
+                          color: Colors.black87,
102
+                        ),
103
+                      ),
104
+                    ),
105
+                  ],
50
                 ),
106
                 ),
51
-                child: Text(
52
-                  texto,
53
-                  style: const TextStyle(fontSize: 16, height: 1.5),
54
-                  textAlign: TextAlign.justify,
107
+                const SizedBox(height: 20),
108
+                Container(
109
+                  padding: const EdgeInsets.all(16),
110
+                  decoration: BoxDecoration(
111
+                    color: Colors.white,
112
+                    borderRadius: BorderRadius.circular(12),
113
+                  ),
114
+                  child: Text(
115
+                    widget.texto,
116
+                    style: const TextStyle(fontSize: 16, height: 1.5),
117
+                    textAlign: TextAlign.justify,
118
+                  ),
55
                 ),
119
                 ),
56
-              ),
57
-            ],
120
+              ],
121
+            ),
58
           ),
122
           ),
59
         ),
123
         ),
60
       ),
124
       ),
61
-    ),
62
-  );
125
+    );
126
+  }
63
 }
127
 }