aplicacion terminada, fondo verde

This commit is contained in:
2024-06-03 15:45:35 +02:00
parent 20a4cb7ab2
commit be701d6e50
7 changed files with 70 additions and 105 deletions

View File

@ -29,7 +29,6 @@ Future<List<String>> obtenerDatos() async {
embalsesData.add(elemento.text);
}
}
return embalsesData;
} else {
throw Exception('Error al cargar los datos de embalses');

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

View File

@ -27,5 +27,4 @@ class MyApp extends StatelessWidget {
home: const MyHomePage(title: 'COMUNIDAD DE REGANTES DE CIVÁN'),
);
}
//comentario
}

View File

@ -14,8 +14,8 @@ class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const CustomAppBar(),
body: BackgroundWidget(
appBar: const CustomAppBar(), //Barra superior personalizada
body: BackgroundWidget( //Widget fondo del fichero BackgroundWidget
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
@ -25,7 +25,7 @@ class MyHomePage extends StatelessWidget {
context,
MaterialPageRoute(builder: (context) => const NoticiasPage()),
);},
child: SizedBox(
child: SizedBox( //Botón Noticias
width: 300.0,
child: Padding(
padding: const EdgeInsets.only(bottom: 20.0),
@ -55,7 +55,7 @@ class MyHomePage extends StatelessWidget {
MaterialPageRoute(builder: (context) => const Pregon()),
);
},
child: SizedBox(
child: SizedBox(//Botón Pregón
width: 300.0,
child: Padding(
padding: const EdgeInsets.only(bottom: 20.0),
@ -85,7 +85,7 @@ class MyHomePage extends StatelessWidget {
MaterialPageRoute(builder: (context) => const EmbalsesPage()),
);
},
child: SizedBox(
child: SizedBox( //Botón Embalses
width: 300.0,
child: Padding(
padding: const EdgeInsets.only(bottom: 20.0),
@ -110,9 +110,9 @@ class MyHomePage extends StatelessWidget {
),
InkWell(
onTap: () {
launchAemetURL();
launchAemetURL();//Función a link externo
},
child: SizedBox(
child: SizedBox(//Botón Tiempo
width: 300.0,
child: Padding(
padding: const EdgeInsets.only(bottom: 20.0),
@ -139,7 +139,7 @@ class MyHomePage extends StatelessWidget {
),
),
),
bottomNavigationBar: const CustomBottomBar(),
bottomNavigationBar: const CustomBottomBar(),//Barra inferior personalizada
);
}
}

View File

@ -5,7 +5,6 @@ import 'package:flutter_project/bars/bottom_bar';
import 'package:html/parser.dart' as htmlParser;
import 'package:flutter_project/widgets/background_widget.dart';
class NoticiasPage extends StatefulWidget {
const NoticiasPage({Key? key}) : super(key: key);
@ -14,75 +13,53 @@ class NoticiasPage extends StatefulWidget {
}
class _NoticiasPageState extends State<NoticiasPage> {
Map<String, List<Future<String>>> noticiasPorTitulo = {};
List<Map<String, String>> noticias = [];
bool _isLoading = true;
static const String url = 'http://www.crcivan.com/escaparate/noticias.cgi?idpadre=92776&idempresa=31637';
@override
void initState() {
super.initState();
obtenerDatos();
obtenerNoticias();
}
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 tituloElements = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > b > a');
for (int i = 0; i < tituloElements.length; i++) {
String titulo = tituloElements[i].text.trim();
// Extrayendo el enlace href del elemento <a>
var linkElement = tituloElements[i];
String? link = linkElement.attributes['href'];
if (link != null) {
noticiasPorTitulo[titulo] = [cargarContenidoUrl(link)];
}
}
await Future.wait(noticiasPorTitulo.values.expand((element) => element).toList());
setState(() {});
} else {
throw Exception('Fallo al cargar noticias');
}
}
Future<String> cargarContenidoUrl(String url) async {
Future<void> obtenerNoticias() async {
try {
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
var document = htmlParser.parse(response.body);
var paragraphAndLists = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > p, html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > ul');
var noticiasElements = document.querySelectorAll(
'html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td'
);
String content = '';
String currentParagraphContent = '';
var noticiasTemp = <Map<String, String>>[];
for (var element in paragraphAndLists) {
if (element.localName == 'p') {
if (currentParagraphContent.isNotEmpty) {
content += currentParagraphContent + '\n';
currentParagraphContent = '';
}
currentParagraphContent += element.text.trim() + '\n';
} else if (element.localName == 'ul') {
if (currentParagraphContent.isNotEmpty) {
content += currentParagraphContent + '\n';
currentParagraphContent = '';
}
var listItems = element.querySelectorAll('li');
for (var listItem in listItems) {
content += '- ${listItem.text.trim()}\n';
for (var element in noticiasElements) {
var tituloElement = element.querySelector('b > a');
if (tituloElement != null) {
var titulo = tituloElement.text.trim();
var contenido = '';
var fontElements = element.querySelectorAll('font');
for (var font in fontElements) {
contenido += '${font.text.trim()}\n';
}
noticiasTemp.add({'titulo': titulo, 'contenido': contenido.trim()});
}
}
if (currentParagraphContent.isNotEmpty) {
content += currentParagraphContent + '\n';
}
return content;
setState(() {
noticias = noticiasTemp;
_isLoading = false;
});
} else {
throw Exception('Fallo al cargar contenido de URL: $url');
throw Exception('Fallo al cargar noticias');
}
} catch (e) {
print('Error al obtener noticias: $e');
setState(() {
_isLoading = false;
});
}
}
@ -90,45 +67,34 @@ class _NoticiasPageState extends State<NoticiasPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: const CustomAppBar(),
body: BackgroundWidget(
body: _isLoading
? Center(child: CircularProgressIndicator())
: BackgroundWidget(
child: ListView.builder(
itemCount: noticiasPorTitulo.length,
itemCount: noticias.length,
itemBuilder: (context, index) {
String titulo = noticiasPorTitulo.keys.elementAt(index);
List<Future<String>>? noticias = noticiasPorTitulo[titulo];
var titulo = noticias[index]['titulo'];
var contenido = noticias[index]['contenido'];
return FutureBuilder<List<String>>(
future: Future.wait(noticias ?? []),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (!snapshot.hasData) {
return Text('No hay datos');
} else {
return Container(
color: Colors.white.withOpacity(0.5), // Fondo blanco con 50% de opacidad
margin: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8.0),
child: ExpansionTile(
title: Text(
titulo,
style: TextStyle(fontWeight: FontWeight.bold),
titulo!,
style: TextStyle(fontWeight: FontWeight.bold), // Establecer negrita para el título
),
children: snapshot.data!.map((noticia) {
return Padding(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
noticia,
style: TextStyle(fontSize: 16.0),
contenido!,
style: TextStyle(fontSize: 16.0), // Mantener el texto del contenido en estilo regular
),
);
}).toList(),
),
);
}
},
],
),
);
},
),
@ -137,3 +103,4 @@ class _NoticiasPageState extends State<NoticiasPage> {
);
}
}

View File

@ -83,7 +83,7 @@ class _PregonState extends State<Pregon> {
datos[index],
textAlign: TextAlign.center,
style: TextStyle(
color: hasMes ? Color.fromARGB(255, 0, 0, 0) : Color.fromARGB(255, 0, 0, 0), fontWeight : FontWeight.bold, fontSize : 22.0
color: hasMes ? Color.fromARGB(255, 0, 0, 0) : Color.fromARGB(255, 0, 0, 0), fontSize : 22.0
),
),
),