add home and detail conference
This commit is contained in:
parent
5ffec90278
commit
19d2968b8c
|
|
@ -1,6 +1,33 @@
|
||||||
// Models of Conferences for MarkDown Text
|
class TranslationModel {
|
||||||
|
final int id;
|
||||||
|
final String language;
|
||||||
|
final String title;
|
||||||
|
final String? markdown;
|
||||||
|
|
||||||
import 'dart:ffi';
|
TranslationModel({
|
||||||
|
required this.id,
|
||||||
|
required this.language,
|
||||||
|
required this.title,
|
||||||
|
this.markdown,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'language': language,
|
||||||
|
'title': title,
|
||||||
|
'markdown': markdown,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
factory TranslationModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return TranslationModel(
|
||||||
|
id: json['id'] ?? 0,
|
||||||
|
language: json['language'] ?? '',
|
||||||
|
title: json['title'] ?? '',
|
||||||
|
markdown: json['markdown'] ?? '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ConferencesModel {
|
class ConferencesModel {
|
||||||
|
|
||||||
|
|
@ -14,8 +41,8 @@ class ConferencesModel {
|
||||||
String state;
|
String state;
|
||||||
String country;
|
String country;
|
||||||
// List<String> type;
|
// List<String> type;
|
||||||
String thumb;
|
String thumbnail;
|
||||||
// List<String> translations;
|
List<TranslationModel> translations;
|
||||||
|
|
||||||
ConferencesModel({
|
ConferencesModel({
|
||||||
required this.id,
|
required this.id,
|
||||||
|
|
@ -28,8 +55,8 @@ class ConferencesModel {
|
||||||
this.state = '',
|
this.state = '',
|
||||||
this.country = '',
|
this.country = '',
|
||||||
// this.type = const [],
|
// this.type = const [],
|
||||||
this.thumb = '',
|
this.thumbnail = '',
|
||||||
// this.translations = const [],
|
this.translations = const [],
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
|
|
@ -44,16 +71,16 @@ class ConferencesModel {
|
||||||
'state': state,
|
'state': state,
|
||||||
'country': country,
|
'country': country,
|
||||||
// 'type': type,
|
// 'type': type,
|
||||||
'thumb': thumb.toString(),
|
'thumbnail': thumbnail.toString(),
|
||||||
// 'translations': translations,
|
'translations': translations.toString() ,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
factory ConferencesModel.fromJson(Map<String, dynamic> json) {
|
factory ConferencesModel.fromJson(Map<String, dynamic> json) {
|
||||||
return ConferencesModel(
|
return ConferencesModel(
|
||||||
id: json['id'],
|
id: json['id'] ?? 0,
|
||||||
title: json['title'],
|
title: json['title'] ?? '',
|
||||||
date: DateTime.parse(json['date'] as String),
|
date: json['date'] != null ? DateTime.parse(json['date'].toString()) : DateTime.now(),
|
||||||
activity: json['activity'] ?? 0,
|
activity: json['activity'] ?? 0,
|
||||||
duration: json['duration'] ?? 0,
|
duration: json['duration'] ?? 0,
|
||||||
place: json['place'] ?? '',
|
place: json['place'] ?? '',
|
||||||
|
|
@ -61,8 +88,10 @@ class ConferencesModel {
|
||||||
state: json['state'] ?? '',
|
state: json['state'] ?? '',
|
||||||
country: json['country'] ?? '',
|
country: json['country'] ?? '',
|
||||||
// type: List<String>.from(json['type'] ?? []),
|
// type: List<String>.from(json['type'] ?? []),
|
||||||
thumb: json['thumb'] ?? '',
|
thumbnail: json['thumbnail'] ?? '',
|
||||||
// translations: List<String>.from(json['translations'] ?? []),
|
translations: (json['translations'] as List<dynamic>?)
|
||||||
|
?.map((item) => TranslationModel.fromJson(item as Map<String, dynamic>))
|
||||||
|
.toList() ?? [],
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,22 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_html/flutter_html.dart';
|
||||||
import 'package:lgcc/models/conferences_model.dart';
|
import 'package:lgcc/models/conferences_model.dart';
|
||||||
import 'package:lgcc/providers/directus_service.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 {
|
class ConferencesPage extends StatelessWidget {
|
||||||
const ConferencesPage({Key? key}) : super(key: key);
|
final dynamic confereceDetail;
|
||||||
|
|
||||||
|
const ConferencesPage({super.key, this.confereceDetail});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Conferencias', style: TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold)),
|
title: const Text('Conferencias'),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
shadowColor: Colors.transparent,
|
backgroundColor: Color(0xFFE5EBFD),
|
||||||
backgroundColor: Colors.blue,
|
|
||||||
|
|
||||||
),
|
),
|
||||||
body: _buildConferenceListView(),
|
body: _buildConferenceListView(),
|
||||||
);
|
);
|
||||||
|
|
@ -22,34 +25,64 @@ class ConferencesPage extends StatelessWidget {
|
||||||
|
|
||||||
Widget _buildConferenceListView() {
|
Widget _buildConferenceListView() {
|
||||||
final DirectusService _directusService = DirectusService();
|
final DirectusService _directusService = DirectusService();
|
||||||
|
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: Future.wait([
|
future: Future.wait([_directusService.getConferences()]),
|
||||||
_directusService.getConferences(),
|
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
|
||||||
]),
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> snapshot) {
|
return const Center(child: CircularProgressIndicator());
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
} else if (snapshot.hasError) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
print('Error: ${snapshot.error}');
|
||||||
} else if (snapshot.hasError) {
|
return Center(child: Text('Error: ${snapshot.error}'));
|
||||||
print('Error: ${snapshot.error}');
|
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||||
return Center(child: Text('Error: ${snapshot.error}'));
|
return const Center(child: Text('No conferences found.'));
|
||||||
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
} else {
|
||||||
return const Center(child: Text('No conferences found.'));
|
List<ConferencesModel> conferences = List<ConferencesModel>.from(
|
||||||
} else {
|
snapshot.data![0],
|
||||||
List<ConferencesModel> conferences = List<ConferencesModel>.from(snapshot.data![0]);
|
);
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: conferences.length,
|
itemCount: conferences.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final conference = conferences[index];
|
final conference = conferences[index];
|
||||||
return ListTile(
|
String urlImage;
|
||||||
title: Text(conference.title, style: const TextStyle(fontSize: 18)),
|
if (conference.thumbnail.isEmpty) {
|
||||||
subtitle: Text(
|
urlImage =
|
||||||
'${conference.date.toLocal().toString().split(' ')[0]} - ${conference.place}, ${conference.city}, ${conference.state}, ${conference.country}, ${conference.activity}',
|
'https://ik.imagekit.io/lgccc/tr:w-1920,f-auto/youtube_thumbnail_46396.png';
|
||||||
style: const TextStyle(fontSize: 16),
|
} 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)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_html/flutter_html.dart';
|
||||||
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
|
import 'package:lgcc/models/conferences_model.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
class DetailConference extends StatelessWidget {
|
||||||
|
final ConferencesModel conference;
|
||||||
|
const DetailConference({super.key, required this.conference});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
// Check if the conference has a thumbnail, if not use a default image
|
||||||
|
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']}';
|
||||||
|
}
|
||||||
|
|
||||||
|
final formattedDate = DateFormat.yMMMMEEEEd().format(conference.date);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Conferencias'),
|
||||||
|
centerTitle: true,
|
||||||
|
backgroundColor: Color(0xFFE5EBFD),
|
||||||
|
),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Image.network(urlImage),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
conference.title,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
height: 1.2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
formattedDate,
|
||||||
|
style: const TextStyle(fontSize: 16, color: Colors.black),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${conference.place}, ${conference.city}, ${conference.state}, ${conference.country}',
|
||||||
|
style: const TextStyle(fontSize: 16, color: Colors.black),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'Actividad: ${conference.activity}',
|
||||||
|
style: const TextStyle(fontSize: 16, color: Colors.black),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ class DirectusService {
|
||||||
Future<List<dynamic>> getConferences() async {
|
Future<List<dynamic>> getConferences() async {
|
||||||
final String baseUrl = dotenv.env['DIRECTUS_API_URL']!;
|
final String baseUrl = dotenv.env['DIRECTUS_API_URL']!;
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse('$baseUrl/items/conferences?fields=*&access_token=${dotenv.env['DIRECTUS_API_TOKEN']}'),
|
Uri.parse('$baseUrl/items/conferences?fields=*,translations.markdown&access_token=${dotenv.env['DIRECTUS_API_TOKEN']}'),
|
||||||
);
|
);
|
||||||
assert(() {
|
assert(() {
|
||||||
print('Response status code: ${response.statusCode}');
|
print('Response status code: ${response.statusCode}');
|
||||||
|
|
|
||||||
32
pubspec.lock
32
pubspec.lock
|
|
@ -1,6 +1,14 @@
|
||||||
# Generated by pub
|
# Generated by pub
|
||||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||||
packages:
|
packages:
|
||||||
|
args:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: args
|
||||||
|
sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.7.0"
|
||||||
async:
|
async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -110,6 +118,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.0.0"
|
version: "5.0.0"
|
||||||
|
flutter_markdown:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_markdown
|
||||||
|
sha256: "08fb8315236099ff8e90cb87bb2b935e0a724a3af1623000a9cec930468e0f27"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.7.7+1"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|
@ -139,6 +155,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.1.2"
|
version: "4.1.2"
|
||||||
|
intl:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: intl
|
||||||
|
sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.20.2"
|
||||||
leak_tracker:
|
leak_tracker:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -179,6 +203,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.2"
|
version: "1.0.2"
|
||||||
|
markdown:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: markdown
|
||||||
|
sha256: "935e23e1ff3bc02d390bad4d4be001208ee92cc217cb5b5a6c19bc14aaa318c1"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "7.3.0"
|
||||||
matcher:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@ dependencies:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_dotenv: ^5.2.1
|
flutter_dotenv: ^5.2.1
|
||||||
flutter_html: ^3.0.0
|
flutter_html: ^3.0.0
|
||||||
|
flutter_markdown: ^0.7.7+1
|
||||||
http: ^1.4.0
|
http: ^1.4.0
|
||||||
|
intl: ^0.20.2
|
||||||
path: ^1.9.1
|
path: ^1.9.1
|
||||||
path_provider: ^2.1.5
|
path_provider: ^2.1.5
|
||||||
sqflite: ^2.4.2
|
sqflite: ^2.4.2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue