noticias creada, embalses necesita tabla y pregones separados por dividers
This commit is contained in:
@ -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<MyState> {
|
||||
MyBloc() : super(MyState());
|
||||
|
||||
}
|
||||
Future<void> launchAemetURL() async {
|
||||
|
||||
Future<void> launchAemetURL() async {
|
||||
const urlString = 'https://www.aemet.es/es/eltiempo/prediccion/municipios/caspe-id50074';
|
||||
final url = Uri.parse(urlString);
|
||||
|
||||
|
||||
0
lib/BloC/estados
Normal file
0
lib/BloC/estados
Normal file
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -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(
|
||||
|
||||
135
lib/pages/embalses
Normal file
135
lib/pages/embalses
Normal file
@ -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<EmbalsesPage> {
|
||||
List<String> embalsesData = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
obtenerDatos();
|
||||
}
|
||||
|
||||
Future<void> 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 <span> 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 <span> 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(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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: <Widget>[
|
||||
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(
|
||||
62
lib/pages/noticias
Normal file
62
lib/pages/noticias
Normal file
@ -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<NoticiasPage> {
|
||||
List<String> noticiasData = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
obtenerDatos();
|
||||
}
|
||||
|
||||
Future<void> 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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
106
lib/pages/pregon
Normal file
106
lib/pages/pregon
Normal file
@ -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<Pregon> {
|
||||
List<String> datos = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
obtenerDatos();
|
||||
}
|
||||
|
||||
Future<void> 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 <p> 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 <p> 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(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -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<String> 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
18
pubspec.lock
18
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"
|
||||
|
||||
@ -37,6 +37,7 @@ dependencies:
|
||||
|
||||
|
||||
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^1.0.6
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user