import 'dart:convert'; import 'package:http/http.dart' as http; class ApiService { final String baseUrl = "http://127.0.0.1:8000/api"; // Ganti dengan URL API kamu Future> register(String name, String email, String password) async { final response = await http.post( Uri.parse("$baseUrl/register"), headers: {"Content-Type": "application/json"}, body: jsonEncode({ "name": name, "email": email, "password": password, }), ); if (response.statusCode == 201) { return jsonDecode(response.body); } else { throw Exception("Gagal melakukan registrasi"); } } Future> login(String email, String password) async { final response = await http.post( Uri.parse("$baseUrl/login"), headers: {"Content-Type": "application/json"}, body: jsonEncode({ "email": email, "password": password, }), ); if (response.statusCode == 200) { return jsonDecode(response.body); } else { throw Exception("Email atau password salah"); } } // Fetch categories Future> getCategories() async { final response = await http.get( Uri.parse("$baseUrl/categories"), headers: {"Content-Type": "application/json"}, ); if (response.statusCode == 200) { final data = jsonDecode(response.body); return data['categories']; // Mengembalikan daftar kategori } else { throw Exception("Gagal mengambil data kategori"); } } // Fetch services Future> getServices() async { final response = await http.get( Uri.parse("$baseUrl/services"), headers: {"Content-Type": "application/json"}, ); if (response.statusCode == 200) { final data = jsonDecode(response.body); return data['services']; // Mengembalikan daftar layanan } else { throw Exception("Gagal mengambil data layanan"); } } }