Cambio interfaz home (prueba), error en enlace Tiempo y noticias faltan mejoras
This commit is contained in:
@ -12,8 +12,7 @@ class NoticiasPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _NoticiasPageState extends State<NoticiasPage> {
|
||||
List<String> noticiasData = [];
|
||||
List<String> titulos = [];
|
||||
Map<String, List<String>> noticiasPorTitulo = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -28,14 +27,44 @@ class _NoticiasPageState extends State<NoticiasPage> {
|
||||
var dataElements = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font');
|
||||
var tituloElements = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > b > a');
|
||||
|
||||
setState(() {
|
||||
noticiasData = dataElements.map((element) => element.text.trim()).toList();
|
||||
titulos = tituloElements.map((element) => element.text.trim()).toList();
|
||||
});
|
||||
for (int i = 0; i < tituloElements.length; i++) {
|
||||
String titulo = tituloElements[i].text.trim();
|
||||
String noticia = dataElements[i].text.trim();
|
||||
|
||||
if (!noticiasPorTitulo.containsKey(titulo)) {
|
||||
noticiasPorTitulo[titulo] = [];
|
||||
}
|
||||
noticiasPorTitulo[titulo]?.add(noticia);
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
} else {
|
||||
throw Exception('Failed to load noticias data');
|
||||
throw Exception('fallo al cargar noticias');
|
||||
}
|
||||
}
|
||||
//Función para desplegar noticias desde los contenedores
|
||||
|
||||
/*Future<void> obtenerDatosNoticias() async {
|
||||
var linkElements = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > a');
|
||||
String? link = linkElements[i].attributes['href'];
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
for (int i = 0; i < tituloElements.length; i++) {
|
||||
String titulo = tituloElements[i].text.trim();
|
||||
String noticia = dataElements[i].text.trim();
|
||||
|
||||
if (!noticiasPorTitulo.containsKey(titulo)) {
|
||||
noticiasPorTitulo[titulo] = [];
|
||||
}
|
||||
noticiasPorTitulo[titulo]?.add(noticia);
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
} else {
|
||||
throw Exception('fallo al cargar noticias');
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -49,30 +78,31 @@ class _NoticiasPageState extends State<NoticiasPage> {
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
ListView.builder(
|
||||
itemCount: noticiasData.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (index < titulos.length) {
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(titulos[index], style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(noticiasData[index]),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
// Si el índice está fuera del rango de titulos, muestra un ListTile sin título
|
||||
return ListTile(
|
||||
subtitle: Text(noticiasData[index]),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
ListView.builder(
|
||||
itemCount: noticiasPorTitulo.length,
|
||||
itemBuilder: (context, index) {
|
||||
String titulo = noticiasPorTitulo.keys.elementAt(index);
|
||||
List<String>? noticias = noticiasPorTitulo[titulo];
|
||||
|
||||
return ExpansionTile(
|
||||
title: Text(
|
||||
titulo,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
children: noticias != null
|
||||
? noticias.map((noticia) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
noticia,
|
||||
style: TextStyle(fontSize: 16.0),
|
||||
),
|
||||
);
|
||||
}).toList()
|
||||
: [],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: const CustomBottomBar(),
|
||||
|
||||
Reference in New Issue
Block a user