aplicacion terminada, clase widget creada y separacion bloc
This commit is contained in:
31
lib/BloC/DataService.dart
Normal file
31
lib/BloC/DataService.dart
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:html/parser.dart' as htmlParser;
|
||||||
|
|
||||||
|
class DataService {
|
||||||
|
Future<List<Map<String, dynamic>>> obtenerDatos() async {
|
||||||
|
final response = await http.get(Uri.parse('http://www.crcivan.com/escaparate/noticias.cgi?idnoticias=192683'));
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final document = htmlParser.parse(response.body);
|
||||||
|
|
||||||
|
final filaTabla = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > table > tbody > tr');
|
||||||
|
|
||||||
|
List<Map<String, dynamic>> embalsesData = [];
|
||||||
|
|
||||||
|
for (var fila in filaTabla) {
|
||||||
|
var nombreElemento = fila.querySelector('td > p > span');
|
||||||
|
var elementos = fila.querySelectorAll('td > span');
|
||||||
|
|
||||||
|
if (nombreElemento != null && elementos.isNotEmpty) {
|
||||||
|
var nombre = nombreElemento.text;
|
||||||
|
var listaElementos = elementos.map<String>((elemento) => elemento.text).toList();
|
||||||
|
|
||||||
|
var embalseMap = {'nombre': nombre, 'elementos': listaElementos};
|
||||||
|
embalsesData.add(embalseMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return embalsesData;
|
||||||
|
} else {
|
||||||
|
throw Exception('Error al obtener datos');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,7 +16,7 @@ class MyBloc extends Cubit<MyState> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
//mejorar código
|
//mejorar código
|
||||||
Future<List<String>> obtenerDatos(String url) async {
|
Future<List<String>> obtenerDatos() async {
|
||||||
final response = await http.get(Uri.parse('http://www.crcivan.com/escaparate/noticias.cgi?idnoticias=192683'));
|
final response = await http.get(Uri.parse('http://www.crcivan.com/escaparate/noticias.cgi?idnoticias=192683'));
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final document = htmlParser.parse(response.body);
|
final document = htmlParser.parse(response.body);
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:flutter_project/BloC/DataService.dart';
|
||||||
import 'package:html/parser.dart' as htmlParser;
|
import 'package:html/parser.dart' as htmlParser;
|
||||||
|
import 'package:flutter_project/BloC/contenedores_event.dart';
|
||||||
import 'package:flutter_project/bars/app_bar';
|
import 'package:flutter_project/bars/app_bar';
|
||||||
|
import 'package:flutter_project/widgets/background_widget.dart';
|
||||||
import 'package:flutter_project/bars/bottom_bar';
|
import 'package:flutter_project/bars/bottom_bar';
|
||||||
|
|
||||||
class EmbalsesPage extends StatefulWidget {
|
class EmbalsesPage extends StatefulWidget {
|
||||||
@ -12,7 +15,8 @@ class EmbalsesPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _EmbalsesPageState extends State<EmbalsesPage> {
|
class _EmbalsesPageState extends State<EmbalsesPage> {
|
||||||
List<Map<String, dynamic>> embalsesData = [];
|
final DataService dataService = DataService();
|
||||||
|
List<Map<String, dynamic>> embalsesData = [];
|
||||||
List<String> descripciones = ['Cota (m)', 'Volumen (Hm3)', 'Entrada (l/s)', 'Salida (l/s)'];
|
List<String> descripciones = ['Cota (m)', 'Volumen (Hm3)', 'Entrada (l/s)', 'Salida (l/s)'];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -22,144 +26,84 @@ List<Map<String, dynamic>> embalsesData = [];
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> obtenerDatos() async {
|
Future<void> obtenerDatos() async {
|
||||||
final response = await http.get(Uri.parse('http://www.crcivan.com/escaparate/noticias.cgi?idnoticias=192683'));
|
try {
|
||||||
if (response.statusCode == 200) {
|
final data = await dataService.obtenerDatos();
|
||||||
final document = htmlParser.parse(response.body);
|
|
||||||
|
|
||||||
// Buscar los elementos <span> dentro de la estructura específica
|
|
||||||
final elementosSpan = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > table > tbody > tr > td > span');
|
|
||||||
final nombreEmbalses = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > table > tbody > tr > td > p > span');
|
|
||||||
|
|
||||||
final filaTabla = document.querySelectorAll('html > body > div > center > table > tbody > tr > td > div > center > table > tbody > tr > td > table > tbody > tr > td > font > font > table > tbody > tr');
|
|
||||||
// Limpiar la lista de datos antes de actualizarla
|
|
||||||
setState(() {
|
setState(() {
|
||||||
embalsesData.clear();
|
embalsesData = data;
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
/* for (var i = 0; i < filaTabla.length; i++){
|
print('Error: $e');
|
||||||
var nombre[i] = filaTabla.child('td > p > span');
|
|
||||||
List elemento[i] = filaTabla.child('td > span');
|
|
||||||
embalseData.add(nombre, elemento);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Agregar textos de los elementos <span> a la lista
|
|
||||||
/* for (var i = 0; i < elementosSpan.length; i++) {
|
|
||||||
final elemento = elementosSpan[i];
|
|
||||||
final style = elemento.attributes['style'];
|
|
||||||
if (style != null && style.contains('font-size: 12pt;')) {
|
|
||||||
setState(() {
|
|
||||||
// Verificar si el índice es válido antes de agregar los datos a embalsesData
|
|
||||||
if (i < nombreEmbalses.length) {
|
|
||||||
embalsesData.add({
|
|
||||||
'nombre': nombreEmbalses[i].text,
|
|
||||||
'otroTexto': elemento.text,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
for (var fila in filaTabla) {
|
|
||||||
var nombreElemento = fila.querySelector('td > p > span');
|
|
||||||
var elementos = fila.querySelectorAll('td > span');
|
|
||||||
|
|
||||||
if (nombreElemento != null && elementos.isNotEmpty) {
|
|
||||||
var nombre = nombreElemento.text;
|
|
||||||
var listaElementos = elementos.map<String>((elemento) => elemento.text).toList();
|
|
||||||
|
|
||||||
// Crear un mapa con el nombre del embalse y sus elementos
|
|
||||||
var embalseMap = {'nombre': nombre, 'elementos': listaElementos};
|
|
||||||
|
|
||||||
// Agregar el mapa a la lista de embalsesData
|
|
||||||
setState(() {
|
|
||||||
embalsesData.add(embalseMap);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw Exception('Error al cargar los datos de embalses');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const CustomAppBar(),
|
appBar: const CustomAppBar(),
|
||||||
body: Stack(
|
body: BackgroundWidget(
|
||||||
children: [
|
child: Padding(
|
||||||
// Fondo con la imagen
|
padding: const EdgeInsets.all(8.0),
|
||||||
Positioned.fill(
|
child: ListView.builder(
|
||||||
child: Image(
|
itemCount: embalsesData.length,
|
||||||
image: AssetImage('assets/logo-fondo-verde.png'),
|
itemBuilder: (context, index) {
|
||||||
fit: BoxFit.cover,
|
final embalseData = embalsesData[index];
|
||||||
),
|
final nombreEmbalse = embalseData['nombre'];
|
||||||
),
|
final listaElementos = embalseData['elementos'];
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: ListView.builder(
|
|
||||||
itemCount: embalsesData.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final embalseData = embalsesData[index];
|
|
||||||
final nombreEmbalse = embalseData['nombre'];
|
|
||||||
final listaElementos = embalseData['elementos'];
|
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 8.0),
|
padding: const EdgeInsets.only(bottom: 8.0),
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white.withOpacity(0.5),
|
color: Colors.white.withOpacity(0.5),
|
||||||
borderRadius: BorderRadius.circular(10.0),
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
nombreEmbalse!,
|
nombreEmbalse!,
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
fontSize : 25.0,
|
fontSize: 25.0,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
Row(
|
),
|
||||||
children: [
|
Row(
|
||||||
Expanded(
|
children: [
|
||||||
child: Padding(
|
Expanded(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
child: Padding(
|
||||||
child: Column(
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: Column(
|
||||||
children: List.generate(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
listaElementos.length,
|
children: List.generate(
|
||||||
(index) => Text(
|
listaElementos.length,
|
||||||
'${descripciones[index]}: ${listaElementos[index]}',
|
(index) => Text(
|
||||||
style: TextStyle(
|
'${descripciones[index]}: ${listaElementos[index]}',
|
||||||
fontWeight: FontWeight.normal, fontSize : 20.0
|
style: const TextStyle(
|
||||||
),
|
fontWeight: FontWeight.normal,
|
||||||
|
fontSize: 20.0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
);
|
||||||
),
|
},
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
bottomNavigationBar: const CustomBottomBar(),
|
bottomNavigationBar: const CustomBottomBar(),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -5,8 +5,7 @@ import 'package:flutter_project/BloC/contenedores_event.dart';
|
|||||||
import 'package:flutter_project/pages/noticias';
|
import 'package:flutter_project/pages/noticias';
|
||||||
import 'package:flutter_project/pages/pregon';
|
import 'package:flutter_project/pages/pregon';
|
||||||
import 'package:flutter_project/pages/embalses';
|
import 'package:flutter_project/pages/embalses';
|
||||||
|
import 'package:flutter_project/widgets/background_widget.dart';
|
||||||
|
|
||||||
|
|
||||||
class MyHomePage extends StatelessWidget {
|
class MyHomePage extends StatelessWidget {
|
||||||
const MyHomePage({Key? key, required this.title}) : super(key: key);
|
const MyHomePage({Key? key, required this.title}) : super(key: key);
|
||||||
@ -16,24 +15,16 @@ class MyHomePage extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const CustomAppBar(),
|
appBar: const CustomAppBar(),
|
||||||
body: Container(
|
body: BackgroundWidget(
|
||||||
|
|
||||||
decoration: const BoxDecoration(
|
|
||||||
image: DecorationImage(
|
|
||||||
image: AssetImage('assets/logo-fondo-verde.png'),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
|
|
||||||
),
|
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () { Navigator.push(
|
onTap: () { Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const NoticiasPage()),
|
MaterialPageRoute(builder: (context) => const NoticiasPage()),
|
||||||
);},
|
);},
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 300.0,
|
width: 300.0,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@ -41,14 +32,14 @@ class MyHomePage extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color.fromARGB(255, 78, 169, 6),
|
color: const Color.fromARGB(255, 78, 169, 6),
|
||||||
borderRadius: BorderRadius.circular(7.0),
|
borderRadius: BorderRadius.circular(7.0),
|
||||||
),
|
),
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'Noticias',
|
'Noticias',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Color.fromARGB(255, 255, 255, 255),
|
color: Colors.white,
|
||||||
fontSize: 32.0,
|
fontSize: 32.0,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@ -71,7 +62,7 @@ class MyHomePage extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color.fromARGB(255, 78, 169, 6),
|
color: const Color.fromARGB(255, 78, 169, 6),
|
||||||
borderRadius: BorderRadius.circular(7.0),
|
borderRadius: BorderRadius.circular(7.0),
|
||||||
),
|
),
|
||||||
child: const Text(
|
child: const Text(
|
||||||
@ -101,7 +92,7 @@ class MyHomePage extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color.fromARGB(255, 78, 169, 6),
|
color: const Color.fromARGB(255, 78, 169, 6),
|
||||||
borderRadius: BorderRadius.circular(7.0),
|
borderRadius: BorderRadius.circular(7.0),
|
||||||
),
|
),
|
||||||
child: const Text(
|
child: const Text(
|
||||||
@ -128,7 +119,7 @@ class MyHomePage extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Color.fromARGB(255, 78, 169, 6),
|
color: const Color.fromARGB(255, 78, 169, 6),
|
||||||
borderRadius: BorderRadius.circular(7.0),
|
borderRadius: BorderRadius.circular(7.0),
|
||||||
),
|
),
|
||||||
child: const Text(
|
child: const Text(
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import 'package:http/http.dart' as http;
|
|||||||
import 'package:flutter_project/bars/app_bar';
|
import 'package:flutter_project/bars/app_bar';
|
||||||
import 'package:flutter_project/bars/bottom_bar';
|
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';
|
||||||
|
|
||||||
|
|
||||||
class NoticiasPage extends StatefulWidget {
|
class NoticiasPage extends StatefulWidget {
|
||||||
const NoticiasPage({Key? key}) : super(key: key);
|
const NoticiasPage({Key? key}) : super(key: key);
|
||||||
@ -47,98 +49,89 @@ class _NoticiasPageState extends State<NoticiasPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<String> cargarContenidoUrl(String url) async {
|
Future<String> cargarContenidoUrl(String url) async {
|
||||||
final response = await http.get(Uri.parse(url));
|
final response = await http.get(Uri.parse(url));
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
var document = htmlParser.parse(response.body);
|
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 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 content = '';
|
||||||
String currentParagraphContent = '';
|
String currentParagraphContent = '';
|
||||||
|
|
||||||
for (var element in paragraphAndLists) {
|
for (var element in paragraphAndLists) {
|
||||||
if (element.localName == 'p') {
|
if (element.localName == 'p') {
|
||||||
if (currentParagraphContent.isNotEmpty) {
|
if (currentParagraphContent.isNotEmpty) {
|
||||||
content += currentParagraphContent + '\n';
|
content += currentParagraphContent + '\n';
|
||||||
currentParagraphContent = '';
|
currentParagraphContent = '';
|
||||||
}
|
}
|
||||||
currentParagraphContent += element.text.trim() + '\n';
|
currentParagraphContent += element.text.trim() + '\n';
|
||||||
} else if (element.localName == 'ul') {
|
} else if (element.localName == 'ul') {
|
||||||
if (currentParagraphContent.isNotEmpty) {
|
if (currentParagraphContent.isNotEmpty) {
|
||||||
content += currentParagraphContent + '\n';
|
content += currentParagraphContent + '\n';
|
||||||
currentParagraphContent = '';
|
currentParagraphContent = '';
|
||||||
}
|
}
|
||||||
var listItems = element.querySelectorAll('li');
|
var listItems = element.querySelectorAll('li');
|
||||||
for (var listItem in listItems) {
|
for (var listItem in listItems) {
|
||||||
content += '- ${listItem.text.trim()}\n';
|
content += '- ${listItem.text.trim()}\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (currentParagraphContent.isNotEmpty) {
|
if (currentParagraphContent.isNotEmpty) {
|
||||||
content += currentParagraphContent + '\n';
|
content += currentParagraphContent + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Fallo al cargar contenido de URL: $url');
|
throw Exception('Fallo al cargar contenido de URL: $url');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const CustomAppBar(),
|
appBar: const CustomAppBar(),
|
||||||
body: Stack(
|
body: BackgroundWidget(
|
||||||
children: [
|
child: ListView.builder(
|
||||||
Positioned.fill(
|
itemCount: noticiasPorTitulo.length,
|
||||||
child: Image(
|
itemBuilder: (context, index) {
|
||||||
image: AssetImage('assets/logo-fondo-verde.png'),
|
String titulo = noticiasPorTitulo.keys.elementAt(index);
|
||||||
fit: BoxFit.cover,
|
List<Future<String>>? noticias = noticiasPorTitulo[titulo];
|
||||||
),
|
|
||||||
),
|
|
||||||
ListView.builder(
|
|
||||||
itemCount: noticiasPorTitulo.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
String titulo = noticiasPorTitulo.keys.elementAt(index);
|
|
||||||
List<Future<String>>? noticias = noticiasPorTitulo[titulo];
|
|
||||||
|
|
||||||
return FutureBuilder<List<String>>(
|
return FutureBuilder<List<String>>(
|
||||||
future: Future.wait(noticias ?? []),
|
future: Future.wait(noticias ?? []),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
return CircularProgressIndicator();
|
return CircularProgressIndicator();
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
return Text('Error: ${snapshot.error}');
|
return Text('Error: ${snapshot.error}');
|
||||||
} else if (!snapshot.hasData) {
|
} else if (!snapshot.hasData) {
|
||||||
return Text('No hay datos');
|
return Text('No hay datos');
|
||||||
} else {
|
} else {
|
||||||
return Container(
|
return Container(
|
||||||
color: Colors.white.withOpacity(0.5), // Fondo blanco con 50% de opacidad
|
color: Colors.white.withOpacity(0.5), // Fondo blanco con 50% de opacidad
|
||||||
margin: const EdgeInsets.all(8.0),
|
margin: const EdgeInsets.all(8.0),
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ExpansionTile(
|
child: ExpansionTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
titulo,
|
titulo,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
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(),
|
|
||||||
),
|
),
|
||||||
);
|
children: snapshot.data!.map((noticia) {
|
||||||
}
|
return Padding(
|
||||||
},
|
padding: const EdgeInsets.all(8.0),
|
||||||
);
|
child: Text(
|
||||||
},
|
noticia,
|
||||||
),
|
style: TextStyle(fontSize: 16.0),
|
||||||
],
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
bottomNavigationBar: const CustomBottomBar(),
|
bottomNavigationBar: const CustomBottomBar(),
|
||||||
);
|
);
|
||||||
|
|||||||
102
lib/pages/pregon
102
lib/pages/pregon
@ -4,6 +4,9 @@ import 'package:html/parser.dart' as htmlParser;
|
|||||||
import 'package:html/dom.dart' as htmlDom;
|
import 'package:html/dom.dart' as htmlDom;
|
||||||
import 'package:flutter_project/bars/app_bar';
|
import 'package:flutter_project/bars/app_bar';
|
||||||
import 'package:flutter_project/bars/bottom_bar';
|
import 'package:flutter_project/bars/bottom_bar';
|
||||||
|
import 'package:flutter_project/widgets/background_widget.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Pregon extends StatefulWidget {
|
class Pregon extends StatefulWidget {
|
||||||
const Pregon({Key? key}) : super(key: key);
|
const Pregon({Key? key}) : super(key: key);
|
||||||
@ -35,41 +38,32 @@ class _PregonState extends State<Pregon> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Agregar textos de los elementos <p> a la lista, evitando los que contienen solo espacios
|
// Agregar textos de los elementos <p> a la lista, evitando los que contienen solo espacios
|
||||||
for (var elemento in elementosParrafos) {
|
for (var elemento in elementosParrafos) {
|
||||||
final texto = elemento.text.trim(); // Eliminar espacios al inicio y al final del texto
|
final texto = elemento.text.trim(); // Eliminar espacios al inicio y al final del texto
|
||||||
if (texto.isNotEmpty) {
|
if (texto.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
datos.add(texto);
|
datos.add(texto);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Error al cargar los datos');
|
throw Exception('Error al cargar los datos');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Lista de nombres de los meses del año
|
// Lista de nombres de los meses del año
|
||||||
final meses = [
|
final meses = [
|
||||||
'enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio',
|
'enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio',
|
||||||
'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'
|
'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'
|
||||||
];
|
];
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const CustomAppBar(),
|
appBar: const CustomAppBar(),
|
||||||
body: Stack(
|
body: BackgroundWidget(
|
||||||
children: [
|
child: Center(
|
||||||
// Fondo con la imagen
|
|
||||||
Positioned.fill(
|
|
||||||
child: Image(
|
|
||||||
image: AssetImage('assets/logo-fondo-verde.png'),
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Contenedor para los párrafos
|
|
||||||
Center(
|
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: datos.length,
|
itemCount: datos.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
@ -78,38 +72,36 @@ Widget build(BuildContext context) {
|
|||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
if (hasMes)
|
if (hasMes)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||||
child: Divider(color: Colors.green, thickness: 3.0), // Divider antes del párrafo
|
child: Divider(color: Colors.green, thickness: 3.0), // Divider antes del párrafo
|
||||||
),
|
),
|
||||||
hasText
|
hasText
|
||||||
? ListTile(
|
? ListTile(
|
||||||
title: Center(
|
title: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
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), fontWeight : FontWeight.bold, fontSize : 22.0
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
: SizedBox.shrink(),
|
)
|
||||||
if (hasMes)
|
: SizedBox.shrink(),
|
||||||
Padding(
|
if (hasMes)
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 100.0),
|
Padding(
|
||||||
child: Divider(color: Colors.green, thickness: 1.0), // Divider después del párrafo
|
padding: const EdgeInsets.symmetric(horizontal: 100.0),
|
||||||
),
|
child: Divider(color: Colors.green, thickness: 1.0), // Divider después del párrafo
|
||||||
],
|
),
|
||||||
);
|
],
|
||||||
},
|
);
|
||||||
|
},
|
||||||
shrinkWrap: true, // Ajusta el tamaño de ListView al contenido
|
shrinkWrap: true, // Ajusta el tamaño de ListView al contenido
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
bottomNavigationBar: const CustomBottomBar(),
|
||||||
bottomNavigationBar: const CustomBottomBar(),
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
22
lib/widgets/background_widget.dart
Normal file
22
lib/widgets/background_widget.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class BackgroundWidget extends StatelessWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const BackgroundWidget({required this.child, Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
Positioned.fill(
|
||||||
|
child: Image.asset(
|
||||||
|
'assets/logo-fondo-verde.png',
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user