25 lines
821 B
Dart
25 lines
821 B
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:lgcc/models/conferences_model.dart';
|
|
|
|
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']}'),
|
|
);
|
|
assert(() {
|
|
print('Response status code: ${response.statusCode}');
|
|
return true;
|
|
}());
|
|
if (response.statusCode == 200) {
|
|
final data = jsonDecode(response.body)['data'];
|
|
return data.map((item) => ConferencesModel.fromJson(item)).toList();
|
|
} else {
|
|
throw Exception('Failed to load conferences');
|
|
}
|
|
}
|
|
} |