import 'package:flutter/material.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:lgcc/models/conferences_model.dart'; import 'package:lgcc/providers/directus_service.dart'; import 'package:lgcc/pages/detail_conference.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; class ConferencesPage extends StatelessWidget { final dynamic confereceDetail; const ConferencesPage({super.key, this.confereceDetail}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Conferencias'), centerTitle: true, backgroundColor: Color(0xFFE5EBFD), ), body: _buildConferenceListView(), ); } } Widget _buildConferenceListView() { final DirectusService _directusService = DirectusService(); return FutureBuilder( future: Future.wait([_directusService.getConferences()]), builder: (BuildContext context, AsyncSnapshot> snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: CircularProgressIndicator()); } else if (snapshot.hasError) { print('Error: ${snapshot.error}'); return Center(child: Text('Error: ${snapshot.error}')); } else if (!snapshot.hasData || snapshot.data!.isEmpty) { return const Center(child: Text('No conferences found.')); } else { List conferences = List.from( snapshot.data![0], ); return ListView.builder( itemCount: conferences.length, itemBuilder: (context, index) { final conference = conferences[index]; String urlImage; if (conference.thumbnail.isEmpty) { urlImage = 'https://ik.imagekit.io/lgccc/tr:w-1920,f-auto/youtube_thumbnail_46396.png'; } else { urlImage = 'https://directus.carpa.com/assets/${conference.thumbnail}?access_token=${dotenv.env['DIRECTUS_API_TOKEN']}'; } return InkWell( onTap: () => Navigator.push( context, MaterialPageRoute( builder: (context) => DetailConference(conference: conference), ), ), child: Padding( padding: const EdgeInsets.all(8.0), child: Card( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ Image.network( urlImage, fit: BoxFit.cover, width: double.infinity, height: 200, ), const SizedBox(height: 8), Text(conference.title, style: const TextStyle(fontSize: 18)), ], ), ), ), ), ); }, ); } }, ); }