embalses listos y notificaciones con titulo. Faltan mejoras

This commit is contained in:
2024-05-13 16:53:53 +02:00
parent 4dfb710eba
commit eec626ac3a
2 changed files with 86 additions and 64 deletions

View File

@ -13,6 +13,7 @@ class NoticiasPage extends StatefulWidget {
class _NoticiasPageState extends State<NoticiasPage> {
List<String> noticiasData = [];
List<String> titulos = [];
@override
void initState() {
@ -25,9 +26,11 @@ class _NoticiasPageState extends State<NoticiasPage> {
if (response.statusCode == 200) {
var document = htmlParser.parse(response.body);
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();
});
} else {
throw Exception('Failed to load noticias data');
@ -46,17 +49,33 @@ class _NoticiasPageState extends State<NoticiasPage> {
fit: BoxFit.cover,
),
),
ListView.builder(
itemCount: noticiasData.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(noticiasData[index]),
);
},
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]),
);
}
},
),
],
),
bottomNavigationBar: const CustomBottomBar(),
bottomNavigationBar: const CustomBottomBar(),
);
}
}