Cambio interfaz home (prueba), error en enlace Tiempo y noticias faltan mejoras

This commit is contained in:
2024-05-16 12:28:25 +02:00
parent eec626ac3a
commit 0c1ef39a32
7 changed files with 102 additions and 58 deletions

BIN
assets/logo-fondo-verde.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

View File

@ -40,9 +40,13 @@ Future<void> launchAemetURL() async {
const urlString = 'https://www.aemet.es/es/eltiempo/prediccion/municipios/caspe-id50074'; const urlString = 'https://www.aemet.es/es/eltiempo/prediccion/municipios/caspe-id50074';
final url = Uri.parse(urlString); final url = Uri.parse(urlString);
if (await canLaunchUrl(url)) { try {
await launchUrl(url); if (await canLaunch(urlString)) {
await launch(urlString);
} else { } else {
throw 'Could not launch $urlString'; throw 'Could not launch $urlString';
} }
} catch (e) {
throw Exception('Error al lanzar la URL de Aemet: $e');
}
} }

View File

@ -110,7 +110,7 @@ List<Map<String, dynamic>> embalsesData = [];
padding: const EdgeInsets.only(bottom: 8.0), padding: const EdgeInsets.only(bottom: 8.0),
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white.withOpacity(0.5),
borderRadius: BorderRadius.circular(10.0), borderRadius: BorderRadius.circular(10.0),
), ),
child: Column( child: Column(

View File

@ -20,7 +20,7 @@ class MyHomePage extends StatelessWidget {
decoration: const BoxDecoration( decoration: const BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage('assets/logo-fondo.png'), image: AssetImage('assets/logo-fondo-verde.png'),
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
@ -35,21 +35,21 @@ class MyHomePage extends StatelessWidget {
MaterialPageRoute(builder: (context) => const NoticiasPage()), MaterialPageRoute(builder: (context) => const NoticiasPage()),
);}, );},
child: SizedBox( child: SizedBox(
width: 300.0, width: 250.0,
child: Padding( child: Padding(
padding: const EdgeInsets.only(bottom: 20.0), padding: const EdgeInsets.only(bottom: 20.0),
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Color.fromARGB(255, 43, 102, 150), color: Color.fromARGB(255, 78, 169, 6),
borderRadius: BorderRadius.circular(7.0), borderRadius: BorderRadius.circular(7.0),
), ),
child: const Text( child: const Text(
'Noticias', 'Noticias',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Color.fromARGB(255, 255, 255, 255),
fontSize: 32.0, fontSize: 27.0,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
@ -65,13 +65,13 @@ class MyHomePage extends StatelessWidget {
); );
}, },
child: SizedBox( child: SizedBox(
width: 300.0, width: 250.0,
child: Padding( child: Padding(
padding: const EdgeInsets.only(bottom: 20.0), padding: const EdgeInsets.only(bottom: 20.0),
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Color.fromARGB(255, 43, 102, 150), color: Color.fromARGB(255, 78, 169, 6),
borderRadius: BorderRadius.circular(7.0), borderRadius: BorderRadius.circular(7.0),
), ),
child: const Text( child: const Text(
@ -79,7 +79,7 @@ class MyHomePage extends StatelessWidget {
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 32.0, fontSize: 27.0,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
@ -95,13 +95,13 @@ class MyHomePage extends StatelessWidget {
); );
}, },
child: SizedBox( child: SizedBox(
width: 300.0, width: 250.0,
child: Padding( child: Padding(
padding: const EdgeInsets.only(bottom: 20.0), padding: const EdgeInsets.only(bottom: 20.0),
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Color.fromARGB(255, 43, 102, 150), color: Color.fromARGB(255, 78, 169, 6),
borderRadius: BorderRadius.circular(7.0), borderRadius: BorderRadius.circular(7.0),
), ),
child: const Text( child: const Text(
@ -109,7 +109,7 @@ class MyHomePage extends StatelessWidget {
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 32.0, fontSize: 27.0,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
@ -122,13 +122,13 @@ class MyHomePage extends StatelessWidget {
launchAemetURL(); launchAemetURL();
}, },
child: SizedBox( child: SizedBox(
width: 300.0, width: 250.0,
child: Padding( child: Padding(
padding: const EdgeInsets.only(bottom: 20.0), padding: const EdgeInsets.only(bottom: 20.0),
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Color.fromARGB(255, 43, 102, 150), color: Color.fromARGB(255, 78, 169, 6),
borderRadius: BorderRadius.circular(7.0), borderRadius: BorderRadius.circular(7.0),
), ),
child: const Text( child: const Text(
@ -136,7 +136,7 @@ class MyHomePage extends StatelessWidget {
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 32.0, fontSize: 27.0,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),

View File

@ -12,8 +12,7 @@ class NoticiasPage extends StatefulWidget {
} }
class _NoticiasPageState extends State<NoticiasPage> { class _NoticiasPageState extends State<NoticiasPage> {
List<String> noticiasData = []; Map<String, List<String>> noticiasPorTitulo = {};
List<String> titulos = [];
@override @override
void initState() { 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 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'); 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(() { for (int i = 0; i < tituloElements.length; i++) {
noticiasData = dataElements.map((element) => element.text.trim()).toList(); String titulo = tituloElements[i].text.trim();
titulos = tituloElements.map((element) => element.text.trim()).toList(); String noticia = dataElements[i].text.trim();
});
if (!noticiasPorTitulo.containsKey(titulo)) {
noticiasPorTitulo[titulo] = [];
}
noticiasPorTitulo[titulo]?.add(noticia);
}
setState(() {});
} else { } 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -50,29 +79,30 @@ class _NoticiasPageState extends State<NoticiasPage> {
), ),
), ),
ListView.builder( ListView.builder(
itemCount: noticiasData.length, itemCount: noticiasPorTitulo.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
if (index < titulos.length) { String titulo = noticiasPorTitulo.keys.elementAt(index);
return Column( List<String>? noticias = noticiasPorTitulo[titulo];
children: [
ListTile( return ExpansionTile(
title: Text(titulos[index], style: TextStyle(fontWeight: FontWeight.bold)), title: Text(
titulo,
style: TextStyle(fontWeight: FontWeight.bold),
), ),
ListTile( children: noticias != null
title: Text(noticiasData[index]), ? noticias.map((noticia) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
noticia,
style: TextStyle(fontSize: 16.0),
), ),
],
); );
} else { }).toList()
// 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(),

View File

@ -77,20 +77,29 @@ Widget build(BuildContext context) {
final hasMes = meses.any((mes) => datos[index].toLowerCase().contains(mes)); final hasMes = meses.any((mes) => datos[index].toLowerCase().contains(mes));
return Column( return Column(
children: [ children: [
if (hasMes) Divider(color: Colors.blue, thickness: 3.0), // Divider antes del párrafo if (hasMes)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0), // Add padding to the divider
child: Divider(color: Colors.blue, thickness: 3.0), // Divider antes del párrafo
),
hasText hasText
? ListTile( ? ListTile(
title: Center( title: Center(
child: Text( child: Text(
datos[index], datos[index],
textAlign: TextAlign.center,
style: TextStyle( style: TextStyle(
color: hasMes ? Color.fromARGB(255, 0, 0, 0) : Color.fromARGB(255, 0, 0, 0), color: hasMes ? Color.fromARGB(255, 0, 0, 0) : Color.fromARGB(255, 0, 0, 0), fontWeight : FontWeight.bold
), ),
), ),
), ),
) )
: SizedBox.shrink(), : SizedBox.shrink(),
if (hasMes) Divider(color: Colors.blue, thickness: 1.0), // Divider después del párrafo if (hasMes)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 100.0), // Add padding to the divider
child: Divider(color: Colors.blue, thickness: 1.0), // Divider después del párrafo
),
], ],
); );
}, },

View File

@ -73,6 +73,7 @@ flutter:
- assets/logo-fondo.png - assets/logo-fondo.png
- assets/logo-sin-texto.png - assets/logo-sin-texto.png
- assets/logo-sin-texto.svg - assets/logo-sin-texto.svg
- assets/logo-fondo-verde.png
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see