aplicacion terminada, fondo verde
This commit is contained in:
@ -29,7 +29,6 @@ Future<List<String>> obtenerDatos() async {
|
|||||||
embalsesData.add(elemento.text);
|
embalsesData.add(elemento.text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return embalsesData;
|
return embalsesData;
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Error al cargar los datos de embalses');
|
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'),
|
home: const MyHomePage(title: 'COMUNIDAD DE REGANTES DE CIVÁN'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//comentario
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,8 +14,8 @@ class MyHomePage extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const CustomAppBar(),
|
appBar: const CustomAppBar(), //Barra superior personalizada
|
||||||
body: BackgroundWidget(
|
body: BackgroundWidget( //Widget fondo del fichero BackgroundWidget
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
@ -25,7 +25,7 @@ class MyHomePage extends StatelessWidget {
|
|||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const NoticiasPage()),
|
MaterialPageRoute(builder: (context) => const NoticiasPage()),
|
||||||
);},
|
);},
|
||||||
child: SizedBox(
|
child: SizedBox( //Botón Noticias
|
||||||
width: 300.0,
|
width: 300.0,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 20.0),
|
padding: const EdgeInsets.only(bottom: 20.0),
|
||||||
@ -55,7 +55,7 @@ class MyHomePage extends StatelessWidget {
|
|||||||
MaterialPageRoute(builder: (context) => const Pregon()),
|
MaterialPageRoute(builder: (context) => const Pregon()),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(//Botón Pregón
|
||||||
width: 300.0,
|
width: 300.0,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 20.0),
|
padding: const EdgeInsets.only(bottom: 20.0),
|
||||||
@ -85,7 +85,7 @@ class MyHomePage extends StatelessWidget {
|
|||||||
MaterialPageRoute(builder: (context) => const EmbalsesPage()),
|
MaterialPageRoute(builder: (context) => const EmbalsesPage()),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox( //Botón Embalses
|
||||||
width: 300.0,
|
width: 300.0,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 20.0),
|
padding: const EdgeInsets.only(bottom: 20.0),
|
||||||
@ -110,9 +110,9 @@ class MyHomePage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchAemetURL();
|
launchAemetURL();//Función a link externo
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(//Botón Tiempo
|
||||||
width: 300.0,
|
width: 300.0,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 20.0),
|
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:html/parser.dart' as htmlParser;
|
||||||
import 'package:flutter_project/widgets/background_widget.dart';
|
import 'package:flutter_project/widgets/background_widget.dart';
|
||||||
|
|
||||||
|
|
||||||
class NoticiasPage extends StatefulWidget {
|
class NoticiasPage extends StatefulWidget {
|
||||||
const NoticiasPage({Key? key}) : super(key: key);
|
const NoticiasPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@ -14,75 +13,53 @@ class NoticiasPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _NoticiasPageState extends State<NoticiasPage> {
|
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
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
obtenerDatos();
|
obtenerNoticias();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> obtenerDatos() async {
|
Future<void> obtenerNoticias() async {
|
||||||
final response = await http.get(Uri.parse('http://www.crcivan.com/escaparate/noticias.cgi?idpadre=92776&idempresa=31637'));
|
try {
|
||||||
if (response.statusCode == 200) {
|
final response = await http.get(Uri.parse(url));
|
||||||
var document = htmlParser.parse(response.body);
|
if (response.statusCode == 200) {
|
||||||
var tituloElements = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > b > a');
|
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++) {
|
var noticiasTemp = <Map<String, String>>[];
|
||||||
String titulo = tituloElements[i].text.trim();
|
|
||||||
|
|
||||||
// Extrayendo el enlace href del elemento <a>
|
for (var element in noticiasElements) {
|
||||||
var linkElement = tituloElements[i];
|
var tituloElement = element.querySelector('b > a');
|
||||||
String? link = linkElement.attributes['href'];
|
if (tituloElement != null) {
|
||||||
|
var titulo = tituloElement.text.trim();
|
||||||
if (link != null) {
|
var contenido = '';
|
||||||
noticiasPorTitulo[titulo] = [cargarContenidoUrl(link)];
|
var fontElements = element.querySelectorAll('font');
|
||||||
}
|
for (var font in fontElements) {
|
||||||
}
|
contenido += '${font.text.trim()}\n';
|
||||||
|
}
|
||||||
await Future.wait(noticiasPorTitulo.values.expand((element) => element).toList());
|
noticiasTemp.add({'titulo': titulo, 'contenido': contenido.trim()});
|
||||||
|
|
||||||
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';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (currentParagraphContent.isNotEmpty) {
|
setState(() {
|
||||||
content += currentParagraphContent + '\n';
|
noticias = noticiasTemp;
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw Exception('Fallo al cargar noticias');
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
return content;
|
print('Error al obtener noticias: $e');
|
||||||
} else {
|
setState(() {
|
||||||
throw Exception('Fallo al cargar contenido de URL: $url');
|
_isLoading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,45 +67,34 @@ class _NoticiasPageState extends State<NoticiasPage> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const CustomAppBar(),
|
appBar: const CustomAppBar(),
|
||||||
body: BackgroundWidget(
|
body: _isLoading
|
||||||
|
? Center(child: CircularProgressIndicator())
|
||||||
|
: BackgroundWidget(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: noticiasPorTitulo.length,
|
itemCount: noticias.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
String titulo = noticiasPorTitulo.keys.elementAt(index);
|
var titulo = noticias[index]['titulo'];
|
||||||
List<Future<String>>? noticias = noticiasPorTitulo[titulo];
|
var contenido = noticias[index]['contenido'];
|
||||||
|
|
||||||
return FutureBuilder<List<String>>(
|
return Container(
|
||||||
future: Future.wait(noticias ?? []),
|
color: Colors.white.withOpacity(0.5), // Fondo blanco con 50% de opacidad
|
||||||
builder: (context, snapshot) {
|
margin: const EdgeInsets.all(8.0),
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
padding: const EdgeInsets.all(8.0),
|
||||||
return CircularProgressIndicator();
|
child: ExpansionTile(
|
||||||
} else if (snapshot.hasError) {
|
title: Text(
|
||||||
return Text('Error: ${snapshot.error}');
|
titulo!,
|
||||||
} else if (!snapshot.hasData) {
|
style: TextStyle(fontWeight: FontWeight.bold), // Establecer negrita para el título
|
||||||
return Text('No hay datos');
|
),
|
||||||
} else {
|
children: [
|
||||||
return Container(
|
Padding(
|
||||||
color: Colors.white.withOpacity(0.5), // Fondo blanco con 50% de opacidad
|
|
||||||
margin: const EdgeInsets.all(8.0),
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ExpansionTile(
|
child: Text(
|
||||||
title: Text(
|
contenido!,
|
||||||
titulo,
|
style: TextStyle(fontSize: 16.0), // Mantener el texto del contenido en estilo regular
|
||||||
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(),
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}
|
],
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -137,3 +103,4 @@ class _NoticiasPageState extends State<NoticiasPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,7 @@ class _PregonState extends State<Pregon> {
|
|||||||
datos[index],
|
datos[index],
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
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