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 {
|
||||
|
||||
|
|
@ -14,8 +41,8 @@ class ConferencesModel {
|
|||
String state;
|
||||
String country;
|
||||
// List<String> type;
|
||||
String thumb;
|
||||
// List<String> translations;
|
||||
String thumbnail;
|
||||
List<TranslationModel> translations;
|
||||
|
||||
ConferencesModel({
|
||||
required this.id,
|
||||
|
|
@ -28,8 +55,8 @@ class ConferencesModel {
|
|||
this.state = '',
|
||||
this.country = '',
|
||||
// this.type = const [],
|
||||
this.thumb = '',
|
||||
// this.translations = const [],
|
||||
this.thumbnail = '',
|
||||
this.translations = const [],
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
|
@ -44,16 +71,16 @@ class ConferencesModel {
|
|||
'state': state,
|
||||
'country': country,
|
||||
// 'type': type,
|
||||
'thumb': thumb.toString(),
|
||||
// 'translations': translations,
|
||||
'thumbnail': thumbnail.toString(),
|
||||
'translations': translations.toString() ,
|
||||
};
|
||||
}
|
||||
|
||||
factory ConferencesModel.fromJson(Map<String, dynamic> json) {
|
||||
return ConferencesModel(
|
||||
id: json['id'],
|
||||
title: json['title'],
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
id: json['id'] ?? 0,
|
||||
title: json['title'] ?? '',
|
||||
date: json['date'] != null ? DateTime.parse(json['date'].toString()) : DateTime.now(),
|
||||
activity: json['activity'] ?? 0,
|
||||
duration: json['duration'] ?? 0,
|
||||
place: json['place'] ?? '',
|
||||
|
|
@ -61,8 +88,10 @@ class ConferencesModel {
|
|||
state: json['state'] ?? '',
|
||||
country: json['country'] ?? '',
|
||||
// type: List<String>.from(json['type'] ?? []),
|
||||
thumb: json['thumb'] ?? '',
|
||||
// translations: List<String>.from(json['translations'] ?? []),
|
||||
thumbnail: json['thumbnail'] ?? '',
|
||||
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_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 {
|
||||
const ConferencesPage({Key? key}) : super(key: key);
|
||||
|
||||
final dynamic confereceDetail;
|
||||
|
||||
const ConferencesPage({super.key, this.confereceDetail});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Conferencias', style: TextStyle(color: Colors.white, fontSize: 24, fontWeight: FontWeight.bold)),
|
||||
title: const Text('Conferencias'),
|
||||
centerTitle: true,
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.blue,
|
||||
|
||||
backgroundColor: Color(0xFFE5EBFD),
|
||||
),
|
||||
body: _buildConferenceListView(),
|
||||
);
|
||||
|
|
@ -22,34 +25,64 @@ class ConferencesPage extends StatelessWidget {
|
|||
|
||||
Widget _buildConferenceListView() {
|
||||
final DirectusService _directusService = DirectusService();
|
||||
|
||||
return FutureBuilder(
|
||||
future: Future.wait([
|
||||
_directusService.getConferences(),
|
||||
]),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> 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<ConferencesModel> conferences = List<ConferencesModel>.from(snapshot.data![0]);
|
||||
return ListView.builder(
|
||||
itemCount: conferences.length,
|
||||
itemBuilder: (context, index) {
|
||||
final conference = conferences[index];
|
||||
return ListTile(
|
||||
title: Text(conference.title, style: const TextStyle(fontSize: 18)),
|
||||
subtitle: Text(
|
||||
'${conference.date.toLocal().toString().split(' ')[0]} - ${conference.place}, ${conference.city}, ${conference.state}, ${conference.country}, ${conference.activity}',
|
||||
style: const TextStyle(fontSize: 16),
|
||||
future: Future.wait([_directusService.getConferences()]),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<dynamic>> 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<ConferencesModel> conferences = List<ConferencesModel>.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)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
final String baseUrl = dotenv.env['DIRECTUS_API_URL']!;
|
||||
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(() {
|
||||
print('Response status code: ${response.statusCode}');
|
||||
|
|
|
|||
32
pubspec.lock
32
pubspec.lock
|
|
@ -1,6 +1,14 @@
|
|||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.7.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -110,6 +118,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
|
@ -139,6 +155,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -179,6 +203,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
markdown:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: markdown
|
||||
sha256: "935e23e1ff3bc02d390bad4d4be001208ee92cc217cb5b5a6c19bc14aaa318c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.3.0"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ dependencies:
|
|||
sdk: flutter
|
||||
flutter_dotenv: ^5.2.1
|
||||
flutter_html: ^3.0.0
|
||||
flutter_markdown: ^0.7.7+1
|
||||
http: ^1.4.0
|
||||
intl: ^0.20.2
|
||||
path: ^1.9.1
|
||||
path_provider: ^2.1.5
|
||||
sqflite: ^2.4.2
|
||||
|
|
|
|||
Loading…
Reference in New Issue