82 lines
2.4 KiB
Plaintext
82 lines
2.4 KiB
Plaintext
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 = [];
|
|
List<String> titulos = [];
|
|
|
|
@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');
|
|
var tituloElements = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > b > a');
|
|
|
|
setState(() {
|
|
noticiasData = dataElements.map((element) => element.text.trim()).toList();
|
|
titulos = tituloElements.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) {
|
|
if (index < titulos.length) {
|
|
return Column(
|
|
children: [
|
|
ListTile(
|
|
title: Text(titulos[index], style: TextStyle(fontWeight: FontWeight.bold)),
|
|
),
|
|
ListTile(
|
|
title: Text(noticiasData[index]),
|
|
),
|
|
],
|
|
);
|
|
} else {
|
|
// Si el índice está fuera del rango de titulos, muestra un ListTile sin título
|
|
return ListTile(
|
|
subtitle: Text(noticiasData[index]),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
|
|
|
|
],
|
|
),
|
|
bottomNavigationBar: const CustomBottomBar(),
|
|
);
|
|
}
|
|
}
|