import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:http/http.dart' as http; import 'package:html/parser.dart' as htmlParser; import 'package:html/dom.dart' as htmlDom; import 'package:flutter_project/pages/embalses'; // Define el estado class MyState { } // Define el bloc class MyBloc extends Cubit { MyBloc() : super(MyState()); } //mejorar código Future> obtenerDatos(String url) async { final response = await http.get(Uri.parse('http://www.crcivan.com/escaparate/noticias.cgi?idnoticias=192683')); if (response.statusCode == 200) { final document = htmlParser.parse(response.body); final elementosSpan = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > table > tbody > tr > td > span'); List embalsesData = []; for (var elemento in elementosSpan) { final style = elemento.attributes['style']; if (style != null && style.contains('color: #000000; font-size: 12pt;')) { embalsesData.add(elemento.text); } } return embalsesData; } else { throw Exception('Error al cargar los datos de embalses'); } } Future launchAemetURL() async { const urlString = 'https://www.aemet.es/es/eltiempo/prediccion/municipios/caspe-id50074'; final url = Uri.parse(urlString); 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'); } }