// ignore_for_file: collection_methods_unrelated_type import 'dart:developer'; import 'package:dio/dio.dart'; class Limit { final double dailyLimit; final double usedLimit; Limit({ required this.dailyLimit, required this.usedLimit, }); factory Limit.fromJson(Map json) { return Limit( dailyLimit: json['dailyLimit']!, usedLimit: json['usedLimit']!, ); } } class LimitService { final Dio _dio; LimitService(this._dio); Future getLimit() async { try { final response = await _dio.get('/api/customer/daily-limit'); if (response.statusCode == 200) { log('Response: ${response.data}'); return Limit.fromJson(response.data); } else { throw Exception('Failed to load'); } } on DioException catch (e) { throw Exception('Network error: ${e.message}'); } catch (e) { throw Exception('Unexpected error: ${e.toString()}'); } } void editLimit( double newLimit) async { try { final response = await _dio.post('/api/customer/daily-limit', data: '{"amount": $newLimit}'); if (response.statusCode == 200) { log('Response: ${response.data}'); } else { throw Exception('Failed to load'); } } on DioException catch (e) { throw Exception('Network error: ${e.message}'); } catch (e) { throw Exception('Unexpected error: ${e.toString()}'); } } }