diff --git a/lib/BloC/contenedores_event.dart b/lib/BloC/contenedores_event.dart index afc36f2..8db78d2 100644 --- a/lib/BloC/contenedores_event.dart +++ b/lib/BloC/contenedores_event.dart @@ -1,5 +1,9 @@ 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 { @@ -11,8 +15,8 @@ class MyBloc extends Cubit { MyBloc() : super(MyState()); } -Future launchAemetURL() async { +Future launchAemetURL() async { const urlString = 'https://www.aemet.es/es/eltiempo/prediccion/municipios/caspe-id50074'; final url = Uri.parse(urlString); @@ -21,4 +25,4 @@ Future launchAemetURL() async { } else { throw 'Could not launch $urlString'; } -} +} \ No newline at end of file diff --git a/lib/BloC/estados b/lib/BloC/estados new file mode 100644 index 0000000..e69de29 diff --git a/lib/bars/app_bar b/lib/bars/app_bar index f766588..67f66e0 100644 --- a/lib/bars/app_bar +++ b/lib/bars/app_bar @@ -13,11 +13,11 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { padding: const EdgeInsets.all(8.0), child: Center( child: Padding( - padding: const EdgeInsets.only(top: 30.0), + padding: const EdgeInsets.only(top: 10.0), child: Image.asset( 'assets/logo-civan.png', - height: 150, - width: 150, + height: 200, + width: 200, ), ), ), diff --git a/lib/main/main.dart b/lib/main/main.dart index f5351b1..4780eaa 100644 --- a/lib/main/main.dart +++ b/lib/main/main.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_project/BloC/contenedores_event.dart'; -import '../homePage/my_home_page.dart'; +import '../pages/my_home_page.dart'; + void main() { runApp( diff --git a/lib/pages/embalses b/lib/pages/embalses new file mode 100644 index 0000000..1d0410a --- /dev/null +++ b/lib/pages/embalses @@ -0,0 +1,135 @@ +import 'package:flutter/material.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/bars/app_bar'; +import 'package:flutter_project/bars/bottom_bar'; + +class EmbalsesPage extends StatefulWidget { + const EmbalsesPage({Key? key}) : super(key: key); + + @override + _EmbalsesPageState createState() => _EmbalsesPageState(); +} + +class _EmbalsesPageState extends State { + List embalsesData = []; + + @override + void initState() { + super.initState(); + obtenerDatos(); + } + + Future obtenerDatos() 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); + + // Buscar los elementos dentro de la estructura específica + 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'); + + // Limpiar la lista de datos antes de actualizarla + setState(() { + embalsesData.clear(); + }); + + // Agregar textos de los elementos a la lista + for (var elemento in elementosSpan) { + final style = elemento.attributes['style']; + if (style != null && style.contains('color: #000000; font-size: 12pt;')) { + setState(() { + embalsesData.add(elemento.text); + }); + } + } + } else { + throw Exception('Error al cargar los datos de embalses'); + } + } + + @override +Widget build(BuildContext context) { + return Scaffold( + appBar: const CustomAppBar(), + body: Stack( + children: [ + // Fondo con la imagen + Positioned.fill( + child: Image( + image: AssetImage('assets/logo-fondo.png'), + fit: BoxFit.cover, + ), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: ListView.builder( + itemCount: embalsesData.length, + itemBuilder: (context, index) { + final embalse = embalsesData[index]; + return Padding( + padding: const EdgeInsets.only(bottom: 8.0), + child: Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10.0), + ), + child: Column( + children: [ + Row( + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text( + embalse, + style: TextStyle( + fontWeight: FontWeight.bold, + ), + ), + ), + ), + ], + ), + Row( + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Text( + 'Valor 1', + ), + ), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Text( + 'Valor 2', + ), + ), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Text( + 'Valor 3', + ), + ), + ), + ], + ), + ], + ), + ), + ); + }, + ), + ), + ], + ), + bottomNavigationBar: const CustomBottomBar(), + ); +} + +} diff --git a/lib/homePage/my_home_page.dart b/lib/pages/my_home_page.dart similarity index 89% rename from lib/homePage/my_home_page.dart rename to lib/pages/my_home_page.dart index 2a4577d..6760cd9 100644 --- a/lib/homePage/my_home_page.dart +++ b/lib/pages/my_home_page.dart @@ -2,8 +2,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_project/bars/app_bar'; import 'package:flutter_project/bars/bottom_bar'; import 'package:flutter_project/BloC/contenedores_event.dart'; -import 'package:flutter_project/pregon/pregon'; - +import 'package:flutter_project/pages/noticias'; +import 'package:flutter_project/pages/pregon'; +import 'package:flutter_project/pages/embalses'; @@ -19,7 +20,7 @@ class MyHomePage extends StatelessWidget { decoration: const BoxDecoration( image: DecorationImage( - image: AssetImage('assets/logo-sin-texto.png'), + image: AssetImage('assets/logo-fondo.png'), fit: BoxFit.cover, ), @@ -29,7 +30,10 @@ class MyHomePage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ InkWell( - onTap: () {}, + onTap: () { Navigator.push( + context, + MaterialPageRoute(builder: (context) => const NoticiasPage()), + );}, child: SizedBox( width: 300.0, child: Padding( @@ -84,7 +88,12 @@ class MyHomePage extends StatelessWidget { ), ), InkWell( - onTap: () {}, + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) => const EmbalsesPage()), + ); + }, child: SizedBox( width: 300.0, child: Padding( diff --git a/lib/pages/noticias b/lib/pages/noticias new file mode 100644 index 0000000..cfa55bb --- /dev/null +++ b/lib/pages/noticias @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'package:flutter_project/bars/app_bar'; +import 'package:flutter_project/bars/bottom_bar'; +import 'package:html/parser.dart' as htmlParser; + +class NoticiasPage extends StatefulWidget { + const NoticiasPage({Key? key}) : super(key: key); + + @override + _NoticiasPageState createState() => _NoticiasPageState(); +} + +class _NoticiasPageState extends State { + List noticiasData = []; + + @override + void initState() { + super.initState(); + obtenerDatos(); + } + + 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 dataElements = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font'); + + setState(() { + noticiasData = dataElements.map((element) => element.text.trim()).toList(); + }); + } else { + throw Exception('Failed to load noticias data'); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: const CustomAppBar(), + body: Stack( + children: [ + Positioned.fill( + child: Image( + image: AssetImage('assets/logo-fondo.png'), + fit: BoxFit.cover, + ), + ), + ListView.builder( + itemCount: noticiasData.length, + itemBuilder: (context, index) { + return ListTile( + title: Text(noticiasData[index]), + ); + }, + ), + ], + ), + bottomNavigationBar: const CustomBottomBar(), + ); + } +} diff --git a/lib/pages/pregon b/lib/pages/pregon new file mode 100644 index 0000000..fdfa0d7 --- /dev/null +++ b/lib/pages/pregon @@ -0,0 +1,106 @@ +import 'package:flutter/material.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/bars/app_bar'; +import 'package:flutter_project/bars/bottom_bar'; + +class Pregon extends StatefulWidget { + const Pregon({Key? key}) : super(key: key); + + @override + _PregonState createState() => _PregonState(); +} + +class _PregonState extends State { + List datos = []; + + @override + void initState() { + super.initState(); + obtenerDatos(); + } + + Future obtenerDatos() async { + final response = await http.get(Uri.parse('http://www.crcivan.com/escaparate/noticias.cgi?idnoticias=192680')); + if (response.statusCode == 200) { + final document = htmlParser.parse(response.body); + + // Buscar los elementos

dentro de la estructura específica + final elementosParrafos = document.querySelectorAll('body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > p'); + + // Limpiar la lista de datos antes de actualizarla + setState(() { + datos.clear(); + }); + + // Agregar textos de los elementos

a la lista, evitando los que contienen solo espacios + for (var elemento in elementosParrafos) { + final texto = elemento.text.trim(); // Eliminar espacios al inicio y al final del texto + if (texto.isNotEmpty) { + setState(() { + datos.add(texto); + }); + } + } + + } else { + throw Exception('Error al cargar los datos'); + } + } + +@override +Widget build(BuildContext context) { + // Lista de nombres de los meses del año + final meses = [ + 'enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', + 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre' + ]; + + return Scaffold( + appBar: const CustomAppBar(), + body: Stack( + children: [ + // Fondo con la imagen + Positioned.fill( + child: Image( + image: AssetImage('assets/logo-fondo.png'), + fit: BoxFit.cover, + ), + ), + // Contenedor para los párrafos + Center( + child: ListView.builder( + itemCount: datos.length, + itemBuilder: (context, index) { + final hasText = datos[index].isNotEmpty; + 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 + hasText + ? ListTile( + title: Center( + child: Text( + datos[index], + style: TextStyle( + color: hasMes ? Color.fromARGB(255, 0, 0, 0) : Color.fromARGB(255, 0, 0, 0), + ), + ), + ), + ) + : SizedBox.shrink(), + if (hasMes) Divider(color: Colors.blue, thickness: 1.0), // Divider después del párrafo + ], + ); + }, + shrinkWrap: true, // Ajusta el tamaño de ListView al contenido + ), + ), + ], + ), + bottomNavigationBar: const CustomBottomBar(), + ); +} + +} \ No newline at end of file diff --git a/lib/pregon/pregon b/lib/pregon/pregon deleted file mode 100644 index 13f2543..0000000 --- a/lib/pregon/pregon +++ /dev/null @@ -1,59 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_project/bars/app_bar'; -import 'package:flutter_project/bars/bottom_bar'; - -class Pregon extends StatelessWidget { - const Pregon({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - - List datos = ['Dia 1', 'Dia 2', 'Dia 3', 'Dia 4','Dia 5','Dia 6']; - - return Scaffold( - appBar: const CustomAppBar(), - bottomNavigationBar: const CustomBottomBar(), - body: Stack( - children: [ - // Fondo de pantalla - Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/logo-sin-texto.png"), - fit: BoxFit.cover, - ), - ), - ), - - ListView.builder( - itemCount: datos.length, - itemBuilder: (context, index) { - return Center( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Container( - width: 500, - height: 100, - decoration: BoxDecoration( - color: Colors.blue[200]?.withOpacity(0.9), - borderRadius: BorderRadius.circular(10.0), - ), - child: Center( - child: Text( - datos[index], - style: const TextStyle( - fontSize: 18.0, - fontWeight: FontWeight.bold, - ), - ), - ), - ), - ), - ); - }, - ), - ], - ), - ); - } -} diff --git a/pubspec.lock b/pubspec.lock index ffe0b4a..24b90f9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -57,6 +57,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.18.0" + csslib: + dependency: transitive + description: + name: csslib + sha256: "706b5707578e0c1b4b7550f64078f0a0f19dec3f50a178ffae7006b0a9ca58fb" + url: "https://pub.dev" + source: hosted + version: "1.0.0" cupertino_icons: dependency: "direct main" description: @@ -112,8 +120,16 @@ packages: description: flutter source: sdk version: "0.0.0" + html: + dependency: "direct dev" + description: + name: html + sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a" + url: "https://pub.dev" + source: hosted + version: "0.15.4" http: - dependency: transitive + dependency: "direct dev" description: name: http sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" diff --git a/pubspec.yaml b/pubspec.yaml index 2ca5cc8..b12c669 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,6 +33,7 @@ dependencies: url_launcher: ^6.0.12 flutter_bloc: ^8.1.5 flutter_svg: ^2.0.10+1 + @@ -51,6 +52,8 @@ dev_dependencies: # package. See that file for information about deactivating specific lint # rules and activating additional ones. flutter_lints: ^3.0.0 + http: ^1.2.1 + html: 0.15.4 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec