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