aplicacion terminada, fondo verde
This commit is contained in:
@ -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');
|
||||
|
||||
BIN
lib/assets/logo-fondo-verde.png
Normal file
BIN
lib/assets/logo-fondo-verde.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
@ -27,5 +27,4 @@ class MyApp extends StatelessWidget {
|
||||
home: const MyHomePage(title: 'COMUNIDAD DE REGANTES DE CIVÁN'),
|
||||
);
|
||||
}
|
||||
//comentario
|
||||
}
|
||||
|
||||
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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');
|
||||
Future<void> obtenerNoticias() async {
|
||||
try {
|
||||
final response = await http.get(Uri.parse(url));
|
||||
if (response.statusCode == 200) {
|
||||
var document = htmlParser.parse(response.body);
|
||||
var noticiasElements = document.querySelectorAll(
|
||||
'html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td'
|
||||
);
|
||||
|
||||
for (int i = 0; i < tituloElements.length; i++) {
|
||||
String titulo = tituloElements[i].text.trim();
|
||||
var noticiasTemp = <Map<String, String>>[];
|
||||
|
||||
// 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 {
|
||||
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');
|
||||
|
||||
String content = '';
|
||||
String currentParagraphContent = '';
|
||||
|
||||
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';
|
||||
setState(() {
|
||||
noticias = noticiasTemp;
|
||||
_isLoading = false;
|
||||
});
|
||||
} else {
|
||||
throw Exception('Fallo al cargar noticias');
|
||||
}
|
||||
|
||||
return content;
|
||||
} else {
|
||||
throw Exception('Fallo al cargar contenido de URL: $url');
|
||||
} 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),
|
||||
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), // Establecer negrita para el título
|
||||
),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ExpansionTile(
|
||||
title: Text(
|
||||
titulo,
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
children: snapshot.data!.map((noticia) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
noticia,
|
||||
style: TextStyle(fontSize: 16.0),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
child: Text(
|
||||
contenido!,
|
||||
style: TextStyle(fontSize: 16.0), // Mantener el texto del contenido en estilo regular
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@ -137,3 +103,4 @@ class _NoticiasPageState extends State<NoticiasPage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user