import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:lgcc/models/item_model.dart'; class WordpressService { String getBaseUrlType(String type) { return 'https://${type}wp.carpa.com/v5/items/?cache=false'; } Future> fetchItems(String type) async { final baseUrl = getBaseUrlType(type); final response = await http.get(Uri.parse('$baseUrl&f=list')); print('Fetching items from: $response'); if (response.statusCode == 200) { final List jsonData = json.decode(response.body); return jsonData.map((item) => ItemModel.fromJson(item)).toList(); } else { throw Exception('Failed to load items'); } } Future> fetchYearsParam(String type ) async { final baseUrl = getBaseUrlType(type); final response = await http.get(Uri.parse(baseUrl + '&years')); print('Fetching years from: $baseUrl'); if (response.statusCode == 200) { final List jsonData = json.decode(response.body); return jsonData.map((item) => ResultModel.fromJson(item)).toList(); } else { throw Exception('Failed to load years'); } } }