diff --git a/lib/BloC/contenedores_event.dart b/lib/BloC/contenedores_event.dart index 2f03f08..46f7da2 100644 --- a/lib/BloC/contenedores_event.dart +++ b/lib/BloC/contenedores_event.dart @@ -29,7 +29,6 @@ Future> obtenerDatos() async { embalsesData.add(elemento.text); } } - return embalsesData; } else { throw Exception('Error al cargar los datos de embalses'); diff --git a/lib/assets/logo-fondo-verde.png b/lib/assets/logo-fondo-verde.png new file mode 100644 index 0000000..6daf7ed Binary files /dev/null and b/lib/assets/logo-fondo-verde.png differ diff --git a/lib/main/main.dart b/lib/main/main.dart index 05cb33b..4780eaa 100644 --- a/lib/main/main.dart +++ b/lib/main/main.dart @@ -27,5 +27,4 @@ class MyApp extends StatelessWidget { home: const MyHomePage(title: 'COMUNIDAD DE REGANTES DE CIVÁN'), ); } - //comentario } diff --git a/lib/pages/my_home_page.dart b/lib/pages/my_home_page.dart index b0d6f25..bd4cac3 100644 --- a/lib/pages/my_home_page.dart +++ b/lib/pages/my_home_page.dart @@ -14,8 +14,8 @@ class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: const CustomAppBar(), - body: BackgroundWidget( + appBar: const CustomAppBar(), //Barra superior personalizada + body: BackgroundWidget( //Widget fondo del fichero BackgroundWidget child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -25,7 +25,7 @@ class MyHomePage extends StatelessWidget { context, MaterialPageRoute(builder: (context) => const NoticiasPage()), );}, - child: SizedBox( + child: SizedBox( //Botón Noticias width: 300.0, child: Padding( padding: const EdgeInsets.only(bottom: 20.0), @@ -55,7 +55,7 @@ class MyHomePage extends StatelessWidget { MaterialPageRoute(builder: (context) => const Pregon()), ); }, - child: SizedBox( + child: SizedBox(//Botón Pregón width: 300.0, child: Padding( padding: const EdgeInsets.only(bottom: 20.0), @@ -85,7 +85,7 @@ class MyHomePage extends StatelessWidget { MaterialPageRoute(builder: (context) => const EmbalsesPage()), ); }, - child: SizedBox( + child: SizedBox( //Botón Embalses width: 300.0, child: Padding( padding: const EdgeInsets.only(bottom: 20.0), @@ -110,9 +110,9 @@ class MyHomePage extends StatelessWidget { ), InkWell( onTap: () { - launchAemetURL(); + launchAemetURL();//Función a link externo }, - child: SizedBox( + child: SizedBox(//Botón Tiempo width: 300.0, child: Padding( padding: const EdgeInsets.only(bottom: 20.0), @@ -139,7 +139,7 @@ class MyHomePage extends StatelessWidget { ), ), ), - bottomNavigationBar: const CustomBottomBar(), + bottomNavigationBar: const CustomBottomBar(),//Barra inferior personalizada ); } } diff --git a/lib/pages/noticias b/lib/pages/noticias index 427745f..ab9fad7 100644 --- a/lib/pages/noticias +++ b/lib/pages/noticias @@ -5,7 +5,6 @@ import 'package:flutter_project/bars/bottom_bar'; import 'package:html/parser.dart' as htmlParser; import 'package:flutter_project/widgets/background_widget.dart'; - class NoticiasPage extends StatefulWidget { const NoticiasPage({Key? key}) : super(key: key); @@ -14,75 +13,53 @@ class NoticiasPage extends StatefulWidget { } class _NoticiasPageState extends State { - Map>> noticiasPorTitulo = {}; + List> noticias = []; + bool _isLoading = true; + + static const String url = 'http://www.crcivan.com/escaparate/noticias.cgi?idpadre=92776&idempresa=31637'; @override void initState() { super.initState(); - obtenerDatos(); + obtenerNoticias(); } - Future obtenerDatos() async { - final response = await http.get(Uri.parse('http://www.crcivan.com/escaparate/noticias.cgi?idpadre=92776&idempresa=31637')); - if (response.statusCode == 200) { - var document = htmlParser.parse(response.body); - var tituloElements = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > b > a'); - - for (int i = 0; i < tituloElements.length; i++) { - String titulo = tituloElements[i].text.trim(); - - // Extrayendo el enlace href del elemento - var linkElement = tituloElements[i]; - String? link = linkElement.attributes['href']; + Future obtenerNoticias() async { + try { + final response = await http.get(Uri.parse(url)); + if (response.statusCode == 200) { + var document = htmlParser.parse(response.body); + var noticiasElements = document.querySelectorAll( + 'html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td' + ); - if (link != null) { - noticiasPorTitulo[titulo] = [cargarContenidoUrl(link)]; - } - } + var noticiasTemp = >[]; - await Future.wait(noticiasPorTitulo.values.expand((element) => element).toList()); - - setState(() {}); - } else { - throw Exception('Fallo al cargar noticias'); - } - } - - Future cargarContenidoUrl(String url) async { - final response = await http.get(Uri.parse(url)); - if (response.statusCode == 200) { - var document = htmlParser.parse(response.body); - var paragraphAndLists = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > p, html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > ul'); - - String content = ''; - String currentParagraphContent = ''; - - for (var element in paragraphAndLists) { - if (element.localName == 'p') { - if (currentParagraphContent.isNotEmpty) { - content += currentParagraphContent + '\n'; - currentParagraphContent = ''; - } - currentParagraphContent += element.text.trim() + '\n'; - } else if (element.localName == 'ul') { - if (currentParagraphContent.isNotEmpty) { - content += currentParagraphContent + '\n'; - currentParagraphContent = ''; - } - var listItems = element.querySelectorAll('li'); - for (var listItem in listItems) { - content += '- ${listItem.text.trim()}\n'; + for (var element in noticiasElements) { + var tituloElement = element.querySelector('b > a'); + if (tituloElement != null) { + var titulo = tituloElement.text.trim(); + var contenido = ''; + var fontElements = element.querySelectorAll('font'); + for (var font in fontElements) { + contenido += '${font.text.trim()}\n'; + } + noticiasTemp.add({'titulo': titulo, 'contenido': contenido.trim()}); } } - } - if (currentParagraphContent.isNotEmpty) { - content += currentParagraphContent + '\n'; + setState(() { + noticias = noticiasTemp; + _isLoading = false; + }); + } else { + throw Exception('Fallo al cargar noticias'); } - - return content; - } else { - throw Exception('Fallo al cargar contenido de URL: $url'); + } catch (e) { + print('Error al obtener noticias: $e'); + setState(() { + _isLoading = false; + }); } } @@ -90,45 +67,34 @@ class _NoticiasPageState extends State { Widget build(BuildContext context) { return Scaffold( appBar: const CustomAppBar(), - body: BackgroundWidget( + body: _isLoading + ? Center(child: CircularProgressIndicator()) + : BackgroundWidget( child: ListView.builder( - itemCount: noticiasPorTitulo.length, + itemCount: noticias.length, itemBuilder: (context, index) { - String titulo = noticiasPorTitulo.keys.elementAt(index); - List>? noticias = noticiasPorTitulo[titulo]; + var titulo = noticias[index]['titulo']; + var contenido = noticias[index]['contenido']; - return FutureBuilder>( - future: Future.wait(noticias ?? []), - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - return CircularProgressIndicator(); - } else if (snapshot.hasError) { - return Text('Error: ${snapshot.error}'); - } else if (!snapshot.hasData) { - return Text('No hay datos'); - } else { - return Container( - color: Colors.white.withOpacity(0.5), // Fondo blanco con 50% de opacidad - margin: const EdgeInsets.all(8.0), + return Container( + color: Colors.white.withOpacity(0.5), // Fondo blanco con 50% de opacidad + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), + child: ExpansionTile( + title: Text( + titulo!, + style: TextStyle(fontWeight: FontWeight.bold), // Establecer negrita para el título + ), + children: [ + Padding( padding: const EdgeInsets.all(8.0), - child: ExpansionTile( - title: Text( - titulo, - style: TextStyle(fontWeight: FontWeight.bold), - ), - children: snapshot.data!.map((noticia) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - noticia, - style: TextStyle(fontSize: 16.0), - ), - ); - }).toList(), + child: Text( + contenido!, + style: TextStyle(fontSize: 16.0), // Mantener el texto del contenido en estilo regular ), - ); - } - }, + ), + ], + ), ); }, ), @@ -136,4 +102,5 @@ class _NoticiasPageState extends State { bottomNavigationBar: const CustomBottomBar(), ); } -} \ No newline at end of file +} + diff --git a/lib/pages/pregon b/lib/pages/pregon index dc4f537..4735a09 100644 --- a/lib/pages/pregon +++ b/lib/pages/pregon @@ -83,7 +83,7 @@ class _PregonState extends State { datos[index], textAlign: TextAlign.center, style: TextStyle( - color: hasMes ? Color.fromARGB(255, 0, 0, 0) : Color.fromARGB(255, 0, 0, 0), fontWeight : FontWeight.bold, fontSize : 22.0 + color: hasMes ? Color.fromARGB(255, 0, 0, 0) : Color.fromARGB(255, 0, 0, 0), fontSize : 22.0 ), ), ), diff --git a/pubspec.yaml b/pubspec.yaml index b410027..e719c72 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,7 +33,7 @@ dependencies: url_launcher: ^6.0.12 flutter_bloc: ^8.1.5 flutter_svg: ^2.0.10+1 - +