noticias creada, embalses necesita tabla y pregones separados por dividers
This commit is contained in:
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(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user