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';
final url = Uri.parse(urlString);
if (await canLaunchUrl(url)) {
await launchUrl(url);
try {
if (await canLaunch(urlString)) {
await launch(urlString);
} else {
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),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
color: Colors.white.withOpacity(0.5),
borderRadius: BorderRadius.circular(10.0),
),
child: Column(

View File

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

View File

@ -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) {
@ -50,29 +79,30 @@ class _NoticiasPageState extends State<NoticiasPage> {
),
),
ListView.builder(
itemCount: noticiasData.length,
itemCount: noticiasPorTitulo.length,
itemBuilder: (context, index) {
if (index < titulos.length) {
return Column(
children: [
ListTile(
title: Text(titulos[index], style: TextStyle(fontWeight: FontWeight.bold)),
String titulo = noticiasPorTitulo.keys.elementAt(index);
List<String>? noticias = noticiasPorTitulo[titulo];
return ExpansionTile(
title: Text(
titulo,
style: TextStyle(fontWeight: FontWeight.bold),
),
ListTile(
title: Text(noticiasData[index]),
children: noticias != null
? noticias.map((noticia) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
noticia,
style: TextStyle(fontSize: 16.0),
),
],
);
} else {
// Si el índice está fuera del rango de titulos, muestra un ListTile sin título
return ListTile(
subtitle: Text(noticiasData[index]),
}).toList()
: [],
);
}
},
),
],
),
bottomNavigationBar: const CustomBottomBar(),

View File

@ -77,20 +77,29 @@ Widget build(BuildContext context) {
final hasMes = meses.any((mes) => datos[index].toLowerCase().contains(mes));
return Column(
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
? ListTile(
title: Center(
child: Text(
datos[index],
textAlign: TextAlign.center,
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(),
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-sin-texto.png
- assets/logo-sin-texto.svg
- assets/logo-fondo-verde.png
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see