107 lines
3.7 KiB
Plaintext
107 lines
3.7 KiB
Plaintext
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:crcivan/bars/app_bar';
|
|
import 'package:crcivan/bars/bottom_bar';
|
|
import 'package:crcivan/widgets/background_widget.dart';
|
|
import 'package:crcivan/pages/utils.dart';
|
|
|
|
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('https://crcivan.asociacionador.es/pregon.html'));
|
|
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: BackgroundWidget(
|
|
child: 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)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
|
child: Divider(color: Colors.green, thickness: 3.0), // Divider antes del párrafo
|
|
),
|
|
hasText
|
|
? ListTile(
|
|
title: Center(
|
|
child: Text(
|
|
datos[index],
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
color: hasMes ? Color.fromARGB(255, 0, 0, 0) : Color.fromARGB(255, 0, 0, 0),
|
|
fontSize: getResponsiveFontSize(context, 22.0),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
: SizedBox.shrink(),
|
|
if (hasMes)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 100.0),
|
|
child: Divider(color: Colors.green, thickness: 1.0), // Divider después del párrafo
|
|
),
|
|
],
|
|
);
|
|
},
|
|
shrinkWrap: true, // Ajusta el tamaño de ListView al contenido
|
|
),
|
|
),
|
|
),
|
|
bottomNavigationBar: const CustomBottomBar(),
|
|
);
|
|
}
|
|
} |