aplicacion terminada, clase widget creada y separacion bloc
This commit is contained in:
@ -3,6 +3,8 @@ 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;
|
||||
import 'package:flutter_project/widgets/background_widget.dart';
|
||||
|
||||
|
||||
class NoticiasPage extends StatefulWidget {
|
||||
const NoticiasPage({Key? key}) : super(key: key);
|
||||
@ -47,100 +49,91 @@ class _NoticiasPageState extends State<NoticiasPage> {
|
||||
}
|
||||
|
||||
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 = '';
|
||||
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 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) {
|
||||
content += currentParagraphContent + '\n';
|
||||
}
|
||||
if (currentParagraphContent.isNotEmpty) {
|
||||
content += currentParagraphContent + '\n';
|
||||
}
|
||||
|
||||
return content;
|
||||
} else {
|
||||
throw Exception('Fallo al cargar contenido de URL: $url');
|
||||
return content;
|
||||
} else {
|
||||
throw Exception('Fallo al cargar contenido de URL: $url');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: const CustomAppBar(),
|
||||
body: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Image(
|
||||
image: AssetImage('assets/logo-fondo-verde.png'),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
ListView.builder(
|
||||
itemCount: noticiasPorTitulo.length,
|
||||
itemBuilder: (context, index) {
|
||||
String titulo = noticiasPorTitulo.keys.elementAt(index);
|
||||
List<Future<String>>? noticias = noticiasPorTitulo[titulo];
|
||||
body: BackgroundWidget(
|
||||
child: ListView.builder(
|
||||
itemCount: noticiasPorTitulo.length,
|
||||
itemBuilder: (context, index) {
|
||||
String titulo = noticiasPorTitulo.keys.elementAt(index);
|
||||
List<Future<String>>? noticias = noticiasPorTitulo[titulo];
|
||||
|
||||
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),
|
||||
),
|
||||
children: snapshot.data!.map((noticia) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
noticia,
|
||||
style: TextStyle(fontSize: 16.0),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user